issue with x command

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

issue with x command

[ Edited ]

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?


Accepted Solutions
Solution
‎02-08-2018 07:27 PM
Super User
Posts: 6,543

Re: issue with x command

Posted in reply to swathiprasad

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


All Replies
Solution
‎02-08-2018 07:27 PM
Super User
Posts: 6,543

Re: issue with x command

Posted in reply to swathiprasad

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;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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