LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Replacing \ with "" gives ^ unterminated string (https://www.linuxquestions.org/questions/linux-newbie-8/replacing-%5C-with-gives-%5E-unterminated-string-4175519126/)

threezerous 09-17-2014 01:07 AM

Replacing \ with "" gives ^ unterminated string
 
I am trying to run my custom script on a set of grep results using the command
Code:

<custom script> | grep ^search_query: | awk '{print $NF}'
This return a result like
xyz:test\[Soluta incorrupte id\]

I need to get rid of \ character before I run my script (I am guessing they were added as escape characters)

So I modified my call as
Code:

<custom_script> | grep ^search_query: | awk 'gsub("\","");{print $NF}'
which gives me the error
awk: gsub("\","");{print $NF}
awk: ^ unterminated string

I tried a few other things using sed, but could not make it work.

Any suggestion? Thanks much to all

allend 09-17-2014 02:02 AM

Perhaps?
Code:

<custom_script> | grep ^search_query: | tr -d '\\'

threezerous 09-17-2014 02:43 AM

That worked....thanks much

eklavya 09-17-2014 02:50 AM

Use
Code:

awk '{gsub(/\\/,"")}1'
So your command should be
Code:

<custom_script> | grep ^search_query: | awk '{gsub(/\\/,"")}1'
It works for
Code:

echo "xyz:test\[Soluta incorrupte id\]" | awk '{gsub(/\\/,"")}1'

pan64 09-17-2014 04:29 AM

I do not like that grep|tr|awk -like chains, so:
<custom script> | awk '/^search_query:/ { gsub("\\\\",""); print $NF }'


All times are GMT -5. The time now is 09:35 PM.