Tuesday, 15 January 2013

unix - Linux, capture word between two words -



unix - Linux, capture word between two words -

i have 1 file:

file.txt

101|aaa {rating=1, dept=10, date=10/02/2013, com=11} 106|bbb {rating=2, dept=11, date=10/03/2013, com=11} 103|vvv {rating=3, dept=12, date=10/03/2013, com=11} 102|aaa {rating=1, dept=10, date=10/04/2013, com=11} 109|bbb {rating=2, dept=11, date=10/05/2013, com=11} 104|bbb {rating=2, dept=11, date=10/07/2013, com=11}

i greping based on:

for in `cat file.txt | grep -i "|aaa "` echo `echo $i|cut -d' ' -f1`"|" `sed -n '/date=/,/, com/p' $i` >> output.txt done

this error occurs

"/sysdate=/,/systime/p: no such file or directory"

please help me?

the output should be:

output.txt

101|aaa|10/02/2013 102|aaa|10/04/2013

awk way improve these cases:

$ awk -f"[ =,]" -v ofs="|" '/aaa/{print $1, $9}' 101|aaa|10/02/2013 102|aaa|10/04/2013

this sets field separators either space, = or , , fetches first , 9th fields, whenever text aaa found in line.

unix

No comments:

Post a Comment