LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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: 96

Rep: Reputation: 16
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
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,383

Rep: Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762Reputation: 2762
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: 96

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

Rep: Reputation: 142Reputation: 142
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 Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:11 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
Open Source Consulting | Domain Registration