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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.