sed replcement
I have a line like
127.0.0.1 abc def hij klm nop qrs I want a sed/awk expression which gives me output like (I want the list corresponding to IP to start with nop) 127.0.0.1 nop abc def hij klm qrs |
If the "nop" field always appears in the same position and the number of fields is always the same, you can simply print out the fields in the order you want using awk.
|
No colucix, the nop is not in the same position and the number of fields are not same as well an there could be an entry like nop.amr.com
Sorry for not explainig the question |
Is the entry nop.amr.com always the same or it just contains the string "nop"? In other words you want to match the whole field or just a part of it (the rest is unknown)?
|
it contains the string nop, i want to take out the exact match of nop. nop could be at beginning as well, got stuck tried so many sed combination but didnt work. At last posted here.
|
You can try this in awk:
Code:
/nop/{ |
Code:
awk '{t=$(NF-1); o=$1;$1=$(NF-1)=""; print o,t,$0}' file |
Hey ghostdog74, colucix
This code in not working the file is Code:
192.9.200.1 nop Code:
awk '{ if ($0 ~ /^127.0.0.1/) { x=""; for (i = 2; i<=NF; i++) { if ($i != "nop"){ x="$x" "$i"}}; printf("%s %s\n","127.0.0.1","nop",$x)} else {print}}' test.txt I want the entry against 127.0.0.1 to start with nop |
so what is your final output you want?
|
This is the final output I want
Code:
192.9.200.1 nop |
Code:
{ start = index($0, $2) |
Code:
awk '/127.0.0.1/{ |
All times are GMT -5. The time now is 05:12 PM. |