顯示具有 awk 標籤的文章。 顯示所有文章
顯示具有 awk 標籤的文章。 顯示所有文章

2015年10月2日 星期五

[bash] kill process id by search process name

2014年3月18日 星期二

[AWK] Replace some key string if txt have two same keyword

awk '/1]/{x=NR+18}(NR<=x){print}' /nvram/8/rnddb.ini > /tmp/happy && \
awk '/2]/{x=NR+18}(NR<=x){print}' /nvram/8/rnddb.ini > /tmp/happy1 && \

awk 'BEGIN { FS = "[ \t]+" }; /^ipv4address/{$3="192.168.200.1"}1'  /tmp/happy1 > /tmp/happy2 && \

awk 'BEGIN { FS = "[ \t]+" } ; /^startaddress/{$3="192.168.200.2"}1'  /tmp/happy2 > /tmp/happy3 && \

awk 'BEGIN { FS = "[ \t]+" } ; /^endaddress/{$3="192.168.200.254"}1'  /tmp/happy3 > /tmp/happy4 && \

cat /tmp/happy /tmp/happy4 > /nvram/8/rnddb.ini


Reference :

2013年4月14日 星期日

[awk] Pick up the field which I want


[awk] Pick up the field which I want

Question :

Files happy/stack/include/types.h and happy_build/stack/include/types.h differ



Solution :

awk '{print $2;}' compare_part4.txt # print column 2 of the line

awk -F"/" '{$NF=""; print $0}' # Don't print the last column of the line

sed 's! !/!g' # Replace all of the space to slash



awk '{print $2;}' compare_part4.txt | awk -F"/" '{$NF=""; print $0}' | sed 's! !/!g'



Result :

atheros/offload_stack/include/



 


[awk] Print only specific field

Ex1:

$cat employee.txt
100  Thomas  Manager    Sales       $5,000
200  Jason   Developer  Technology  $5,500
300  Sanjay  Sysadmin   Technology  $7,000
400  Nisha   Manager    Marketing   $9,500
500  Randy   DBA        Technology  $6,000

$ awk '{print $2,$5;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000

$ awk '{print $2,$NF;}' employee.txt
Thomas $5,000
Jason $5,500
Sanjay $7,000
Nisha $9,500
Randy $6,000


$NF represents last field


Ex2 :

$cat employee.txt
100/Thomas/Manager/Sales/$5,000

$ awk -F"/" '{print $2,$NF;}' employee.txt

Reference :

2013年2月3日 星期日

[AWK] How to pickup specific data

Catch column 5
awk -F' ' '{ print $5 }'  ./abc.txt | awk "NR==1{print;exit}"

 # wlanconfig ath0 list sta

ADDR               AID CHAN RATE RSSI IDLE  TXSEQ  RXSEQ CAPS ACAPS ERP    STATE HTCAPS

1c:4b:d6:d0:2e:ee    1    1 145M   63    0    341   7936 EPSs         0        f WPS    RSN WME

Reference :