LinuxQuestions.org
Help answer threads with 0 replies.
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 04-09-2015, 10:22 AM   #1
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 51

Rep: Reputation: Disabled
Smile Sed Command


Hi,

I am not able to replace the $@@$ with ,. below is the content in which i want $@@$ should be replace with ,

"Harbola$@@$ Gopal (ssoid)","agaga"
"Gaurav$@@$ Gaurav (ssoid)","abc"

so that the result can come like this.

"Harbola, Gopal (ssoid)","agaga"
"Gaurav, Gaurav (ssoid)","abc"

Can anyone help me in this
 
Old 04-09-2015, 10:33 AM   #2
Lnthink
Member
 
Registered: May 2010
Location: Lafayette, LA
Distribution: Ubuntu, RH, Fedora
Posts: 39

Rep: Reputation: 8
"Harbola$@@$ Gopal (ssoid)","agaga"
"Gaurav$@@$ Gaurav (ssoid)","abc"

so that the result can come like this.

"Harbola, Gopal (ssoid)","agaga"
"Gaurav, Gaurav (ssoid)","abc"



sed "s/\\$\@\@\\$/,/" < inputfile > outputfile will do it.
 
1 members found this post helpful.
Old 04-09-2015, 10:44 AM   #3
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 51

Original Poster
Rep: Reputation: Disabled
Thanks a lot. Its working fine
 
Old 04-09-2015, 01:41 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,493

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
You can reduce the number of escapes by placing the command in single quotes. Also, the @ symbol does not require escaping.
 
1 members found this post helpful.
Old 04-09-2015, 03:34 PM   #5
Lnthink
Member
 
Registered: May 2010
Location: Lafayette, LA
Distribution: Ubuntu, RH, Fedora
Posts: 39

Rep: Reputation: 8
Quote:
Originally Posted by grail View Post
You can reduce the number of escapes by placing the command in single quotes. Also, the @ symbol does not require escaping.
I tried it without escaping the @ symbols. It seemed to need it for it to work correctly.
Yes, I was surprised by this...
 
Old 04-09-2015, 03:47 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,131

Rep: Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317Reputation: 1317
$@ needs escaping from the shell if it's in double quotes.

Code:
# WRONG: 1 backslash protects from shell escaping, but $ needs to be escaped for sed too
"\$@" -> $@
# WRONG: 1st backslash escapes 2nd one (shell escaping rules for double quoted backslashes are confusing)
"\\$@" -> \
# RIGHT: 1st backslash escapes 2nd one, 3rd escapes $; 1 backslash makes it through to escape the $ for sed
"\\\$@" -> \$@
All of this can be avoided by using single quotes.
 
1 members found this post helpful.
Old 04-10-2015, 08:25 AM   #7
Lnthink
Member
 
Registered: May 2010
Location: Lafayette, LA
Distribution: Ubuntu, RH, Fedora
Posts: 39

Rep: Reputation: 8
Thanks for the single quote tip for sed expressions - I didn't know that.
This will help greatly in the future.

I appreciate it!
 
  


Reply

Tags
sed regex


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
Sed substitution gives error "sed: command garbled" gsai0205 Linux - Newbie 3 09-13-2013 09:01 AM
[SOLVED] sed gives :sed: -e expression #1, char 1: unknown command: `'' samasat Linux - Newbie 10 06-09-2012 05:31 PM
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 12:27 PM
Sed command - command garbled errror gauavmahesh Linux - Newbie 3 03-30-2012 10:04 PM
Modifying text file with "one command line" SED command... daleo Linux - Newbie 3 01-13-2012 05:32 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