Labels

Linux (46) network (13) troubleshoot (13) command (10) virtualization (10) ubuntu (9) Windows (8) cisco (7) security (7) router (6) Tools (5) software (5) vmware (5) ospf (3) eigrp (1) zimbra (1)

2010年1月19日

Linux command - cut, sed, awk

Cut

cut -c 1-7 f1 will output the first 7 characters in each line of file 'f1'.

cut -c 2,4-7,10- f1 will output the character 2, characters 4 – 7, characters 10 until the end of line in each line of file 'f1'.

cut -f 1,4,5 f1 will output 'fields' 1, 4 and 5 in file 'f1'. The fields are assumed to be separated by tab in 'f1'.

cut -d ' ' -f 1,4,5 f1 will output 'fields' 1, 4 and 5 in file 'f1'. The fields are assumed to be separated by a single space in 'f1'.

Sed

Let's make a test file
ls -l /etc > testsed

"d" means delete
sed '1,4d' testsed
sed '/yum/d' testsed
sed '/yum/!d' testsed

"s" is replace, -n means hide the other output, p is display
sed -n 's/pass/xxxxx/p' testsed


Awk
Make another file to test awk
ps aux > testawk

Show column 11
awk '{print $11}' testawk

awk '/sbin/{print $2,$11}' testawk

沒有留言:

張貼留言