BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sfffdg
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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;

View solution in original post

1 REPLY 1
Astounding
PROC Star

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 418 views
  • 0 likes
  • 2 in conversation