LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2014, 01:07 AM   #1
threezerous
Member
 
Registered: Jul 2009
Posts: 92

Rep: Reputation: 15
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

Last edited by threezerous; 09-17-2014 at 01:18 AM.
 
Old 09-17-2014, 02:02 AM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,501

Rep: Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383Reputation: 1383
Perhaps?
Code:
<custom_script> | grep ^search_query: | tr -d '\\'
 
1 members found this post helpful.
Old 09-17-2014, 02:43 AM   #3
threezerous
Member
 
Registered: Jul 2009
Posts: 92

Original Poster
Rep: Reputation: 15
That worked....thanks much
 
Old 09-17-2014, 02:50 AM   #4
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
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'
 
Old 09-17-2014, 04:29 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,645

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Stop bash from replacing "~" with "/home/username" when TAB is pressed dedec0 Linux - Software 3 06-04-2015 01:24 PM
[SOLVED] Replacing a string of text that includes "/" Mike_V Programming 6 09-29-2010 07:21 PM
How to stop bash from replacing "~/" with "/home/username"? daihard Linux - Software 8 08-22-2010 02:32 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration