Showing posts with label awk. Show all posts
Showing posts with label awk. Show all posts

Saturday, November 8, 2008

Linux:shell: awk: multiple separators

'awk' is a very useful shell command (also a program language) in linux (unix). You split one text line by it. For example, for the line

line="aa, b c , d , f "

what you can do in shell command (bash) is

echo $line|awk -F "," '{print $1 $2 $3 $4}' # to get different columns separated by ","

However, if you wanna split one line with multi-separators, then you could do in the way, for example,

$ line="aa, bb_ ccd: ee"
$ echo $line |awk -F ",|_|:" '{print $1$2$3}'

Note here "|" will do logic "OR" of all separators. This is similar 'egrep'. If you want to grep multi key words, then you could do in the same way (which has been addressed in my other blog, just search grep ).

Tuesday, May 13, 2008

Linux:Bash:how to print quotation marks in awk

ls | awk '{print "'\''"$1"'\''"}'

or

awk 'BEGIN { print "Here is a single quote \47" }'

Locations of visitors to this page