regex - Write a regular expression to parse following string -
i using sed
command , want parse following string:
mr. xyz mr. abc, pqr ward-2, abc vs. mg road, pune, pune dist., (appellant) (respondent)
now want parse above string , want appellant part separated above example , respondent part separated.
that want following output:
mr. xyz ward-2, abc(appellant)
1 output , mr. abc, pqr mg road, pune, pune dist.,(respondent)
output using sed
command.
i used following regex not getting proper output:
sed -n '/assessment year/i{ :loop; n; /respondent/iq; p; b loop}' abc.txt
sed wrong tool job involves looking @ multiple lines. use awk, it's invented for. here's gnu awk couple of extensions:
$ cat tst.awk begin { fieldwidths="30 7 99" } { (i=1;i<=nf;i++) { gsub(/^\s*|\s*$/,"",$i) if ($i != "") { rec[i] = (rec[i]=="" ? "" : rec[i] " ") $i } } } /^\(/ { print rec[1] print rec[3] delete rec } $ $ awk -f tst.awk file mr. xyz ward-2, abc (appellant) mr. abc, pqr mg road, pune, pune dist., (respondent)
Comments
Post a Comment