Reputation: 23
I have below script to remove newline character from a | delimited file. This command is working fine in local host . But giving blank output while running on linux server
gawk -v RS="[^|]+([|][^|]+){2}\n" '{ gsub("\n", " ", RT); print RT}'
Below is the output that I am getting on local host
$cat sample.csv
$ No|Name|sal
2|gkdjkh|554
3|fgh
cvb|678
4|tyu|789
5|ghl
tyu|5677
6|yyui
tyui
uui|780
Tarun Pant@GGN000154654002 ~
$ gawk -v RS="[^|]+([|][^|]+){2}\n" '{ gsub("\n", " ", RT); print RT}'
sample.csv
$ No|Name|sal
2|gkdjkh|554
3|fgh cvb|678
4|tyu|789
5|ghl tyu|5677
6|yyui tyui uui|780
Upvotes: 1
Views: 87
Reputation: 204229
RE intervals only became default in gawk 4.0. Change your script to:
gawk --re-interval -v RS='[^|]+([|][^|]+){2}\n' '{ gsub(/\n/, " ", RT); print RT}'
and it'll work in both gawk versions. Or even better just get a current gawk on all your machines.
Upvotes: 1