Popular recipes tagged "awk" but not "perl"http://code.activestate.com/recipes/tags/awk-perl/2011-11-25T17:14:57-08:00ActiveState Code Recipesawk-like module (Python) 2011-11-25T17:14:57-08:00davidhttp://code.activestate.com/recipes/users/4179974/http://code.activestate.com/recipes/577962-awk-like-module/ <p style="color: grey"> Python recipe 577962 by <a href="/recipes/users/4179974/">david</a> (<a href="/recipes/tags/awk/">awk</a>). </p> <p>This python module is similar to awk (pattern scanning and processing language in unix/linux). It scans the input file for lines, split each line to fields. *._nr # AWK NR *._nf # AWK NF *._0r # AWK $0 *._1 # AWK strip($1) *._1r # AWK $1 , raw string *._1i # AWK int($1) *._1f # AWK float($1)</p> Line-oriented processing in Python from command line (like AWK) (Python) 2011-04-14T19:49:16-07:00Artur Siekielskihttp://code.activestate.com/recipes/users/4177664/http://code.activestate.com/recipes/577656-line-oriented-processing-in-python-from-command-li/ <p style="color: grey"> Python recipe 577656 by <a href="/recipes/users/4177664/">Artur Siekielski</a> (<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>A very simple but powerful shell script which enables writing ad-hoc Python scripts for processing line-oriented input. It executes the following code template:</p> <pre class="prettyprint"><code>$INIT for line in sys.stdin: $LOOP $END </code></pre> <p>where $INIT, $LOOP and $END code blocks are given from command line. If only one argument is given, then $INIT and $END are empty. If two arguments are given, $END is empty.</p> <p>Examples (script is saved as 'pyk' in the $PATH):</p> <ul> <li>"wc -l" replacement: $ cat file | pyk 'c=0' 'c+=1' 'print c'</li> <li>grep replacement: $ cat file | pyk 'import re' 'if re.search("\d+", line): print line'</li> <li>adding all numbers: $ seq 1 10 | pyk 's=0' 's+=int(line)' 'print s'</li> <li>prepending lines with it's length: $ cat file | pyk 'print len(line), line'</li> <li>longest file name: $ ls -1 | pyk 'longest=""' 'if len(line) &gt; len(longest): longest=line' 'print longest'</li> <li>number of unique words in a document: $ pyk 'words=[]' 'words.extend(line.split())' 'print "All words: {}, unique: {}".format(len(words), len(set(words))'</li> </ul> scan db to login the ssh servers (Bash) 2010-03-16T13:11:17-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576877-scan-db-to-login-the-ssh-servers/ <p style="color: grey"> Bash recipe 576877 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/awk/">awk</a>, <a href="/recipes/tags/bash/">bash</a>). Revision 2. </p> <p>awk with parameters passed from bash</p> awk sample (Bash) 2010-03-16T13:24:00-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576876-awk-sample/ <p style="color: grey"> Bash recipe 576876 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/awk/">awk</a>). </p> <p>this is an awk sample</p>