Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 172010
 

Multiple separators in awk

Answer:

Sometimes when you split a string using awk, you need to support more than 1 separators, you can use the -F option.

E.g.

# cat foo.txt | awk -F "[ ?]" '{print $7}'

Now the awk split by a space and by a ?.

Jan 272010
 

Extract column data using awk

Answer:

A simple awk command print the 1st column of top command

# top -bc -n1 | awk '{print $1}'

If you want to specify the field separator, you can do the following

# awk -F':' '{print $1}' /etc/passwd

Which print the 1st column of file /etc/password, as if they are split by :