Home    Personal    Work    Computers    Miscellaneous

LaTeX    Software Projects    Rendering Tutorial    UNIX Commands    Using CVS    Case Modding    Base Wiki

Some helpful SED and AWK scripts

I regularly use some simple SED and AWK scripts to simplify life, but I tend to forget the specifics of their syntax, and have to start googling over and over and over in order to find something useful along the lines I want to have. SO here's a collection of stuff that I can easily copy/paste to my Terminal. It may not always be the best way to go about stuff, it simply works, so that's that. Don't complain or contact me with better solutions as I won't really care :)

Split a line into multiple lines

The following AWK oneliner splits a line into multiple lines, for a specific separator (":" in this case)

$ echo "text:text:text" | awk -v RS=":" 'length()==0{next}{print $0}' text text text

$

Swap two columns

The following AWK one liner swaps two columns in an input file, and converts the input separator (FS) to a different output separator (OFS)

$ echo "hello|world > hello|universe" | awk 'BEGIN {FS="|"} {OFS="\t"} {print $2,$1}' world hello universe hello $

Conditionals in multiple columns

Awk can be used to "grep" in columns of a TSV file ...

Here's an example of getting information from a TSV file with various operators

awk '($2=="1") && ($3>=53565901) && ($3<=53566551)' file.tsv

Edit (locked) - History - Recent Changes - Search - Statistics
All contents copyrighted 2000-2006 Anthony Liekens unless otherwise noted. Powered by PmWiki
Page last modified on January 27, 2010, at 01:43 AM.