Hi ,
I need to delete the footer from the file like below and copy to another file.
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
SGW|SGW_CDR_|2017-12-09 174338|2017-12-10 003143|2017-12-09 213311|2017-12-10 013310|39246|0200005649
Total Recs:6
The below linux command is working fine in putty.
awk 'NR>1 && /./ { print buf; buf=rs=""} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }' file1 > file2
but the below x command is giving error :
x " awk 'NR>1 && /./ { print buf; buf=rs=""} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }' file1 > file2 2>&1" ;
The error is:
awk: NR>1 & /./ { print buf; buf=rs="} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }
awk: ^ syntax error
awk: NR>1 & /./ { print buf; buf=rs="} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }
awk: ^ unterminated string
Any Ideas on how to resolve this issue?
You're encountering an issue because the command you want to run contains both single and double quotes. Yet the X command requires its command to be in quotes. That would require changing the command, unless ...
Switch from X to %sysexec. For all practical purposes, it performs the identical function but doesn't require quotes:
%sysexec awk 'NR>1 && /./ { print buf; buf=rs=""} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }' file1 > file2;
You're encountering an issue because the command you want to run contains both single and double quotes. Yet the X command requires its command to be in quotes. That would require changing the command, unless ...
Switch from X to %sysexec. For all practical purposes, it performs the identical function but doesn't require quotes:
%sysexec awk 'NR>1 && /./ { print buf; buf=rs=""} { buf=(buf rs $0); rs=RS } END { if (i=index(buf,RS)) print substr(buf,i+1) }' file1 > file2;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.