Crazy good awk Stuff -------------------- To remove everything but the first column before the space in the a file cat file | awk '/ / {print $1}' > output.txt To remove everything but the first column before the : cat file | awk -F: '{print $1}' > output.txt From http://www.acck.edu/~zjerodp/spellbook.html This is really good so I hope they don't mind I'm borrowing it. Unix command line tricks This page is always being modified. This is a listing of short programs to accomplish small tasks. These were written for the csh on HP-UX 11.0 but should be applicable to any BSD derived system. You will find awk, sed, perl, and vi tricks here. Frequently I work with files containing data that require preparation to use somewhere else. A good way to get familiar is to create some test files filled with data. Here is a sample for you to copy and paste in your text editor. For this page, this file will be called myfile. Ashbourne 14567 Crowley, Tom crowley@fire Belfast 65420 Stewart, Bob stewart@electric Chelmsford 34591 Campbell, Lisa campbell@kinetic Dungannon 11278 Morse, John morse@gravity Edinburgh 2290 Fox, Paul fox@water Fareham 34531 Biggs, Douglass biggs@metal Glasgow 98231 Anderson, Aubrey anderson@air Hastings 4500 Baldauf, Jack baldauf@snuke Ipswich 32578 Brooks, David brooks@mineral Jesmond 44498 Fryxell, Greta fryxell@wood Kensington 90124 North, Gerald north@wnuke London 55812 Pinckney, Jay pinckney@shadow Manchester 98703 Slowey, Niall slowey@plasma Newcastle 89239 Wormuth, John wormuth@earth Display file without the blank lines: awk 'NF > 0' myfile awk '/./' myfile sed -e '/^$/d' myfile perl -ne 'print unless /^ *$/' myfile You can delete the blank lines in vim by entering this command while the cursor is at the top of the file. :g/^$/d Delete blanks (whitespace) at start/end of line: In vim, to remove leading blanks :%s/^ *// In vim, to remove trailing blanks :%s/ *$// This will not remove blanks between words. awk '{sub(/^[ \t]+/, ""); print}' myfile # from start of line awk '{sub(/[ \t]+$/, "");print}' myfile # from end of line sed 's/\ \ *$//' myfile # remove blank space at end of line Insert blanks at start of line. perl -p -i -e "s/$/ /g;" myfile # insert blank space at end of line perl -p -i -e "s/^/ /g;" myfile # insert blank space at start of line Remove first 10 lines in a file: sed '1,10d' myfile Remove the last character in a line in vim: :1,$s/.$// Place a comma at the end of each line: sed 's/$/\,/g' myfile perl -p -i -e "s/\n/\,\n/g;" myfile Insert blank lines in a file: sed G myfile # single blank line between each line sed "G;G" myfile # double blank lines between each line sed "n;n;n;n;G;" myfile # insert blank line after 5 lines, 10 lines, etc. awk '1;{print ""}' myfile # single blank line between each line awk 'NF{print $0 "\n"}' # double blank lines between each line awk '1;{print "\n"}' # triple blank lines Place single quotes around line: sed "s/\(.*\)/'\1'/" myfile Enumerate non-blank lines at the beginning: sed '/./=' myfile | sed '/./N; s/\n/ /' Reverse the order of a file: sed '1!G;h;$!d' myfile # this works in sh not csh perl -e 'print reverse <>' myfile in vim, enter this command: :g/^/m0 Left justify each line: awk '{sub(/^[ \t]+/, ""); print}' myfile Add/remove leading angle bracket at start of line: sed 's/^/> /' myfile sed 's/^> //' myfile Print file without HTML tags (may not be 100% effective): sed -e :a -e 's/<[^>]*>//g;/