Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-01-2015, 09:31 AM   #1
LQ Newbie
Registered: Aug 2013
Posts: 4

Rep: Reputation: Disabled
replace a string containing " with sed

could you please tell me how to use sed in the purpose of replacing a string containing " with an other string , exaple:

my string is "@id": "45002"

i would like to delete all occurence of " and @ and id , finally the output is : 45002

Old 12-01-2015, 10:29 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,692

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
A string containing " is expressed as
but I doubt this is what you want.

Can you be more specific? Do you want to remove all occurrences of " @ i d?

Last edited by berndbausch; 12-01-2015 at 10:37 AM.
Old 12-01-2015, 02:41 PM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
You might think of looking at it from 2 different points:

1. What you want to get rid (current method)

2. What you want to keep (ie search for the number in the line)

Often if you get stuck looking at it from only one point of view you may miss an easier alternative
Old 12-01-2015, 04:23 PM   #4
Senior Member
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Linux Mint, Ubuntu
Posts: 1,599

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Something like this?
# echo '"@id": "45002"' | sed -e 's/["@]//g'  
id: 45002
Old 12-01-2015, 06:58 PM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
echo '"@id": "45002"'|sed -e 's/["a-z@]//g'
: 45002
Old 12-01-2015, 10:40 PM   #6
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
echo '"@id": "45002"' | sed 's/"\|@\|id//g'
: 45002


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 replace string xmickaelx Programming 3 04-07-2011 07:42 AM
how do i replace a text string in a file with a random string? (with sed etc) steve51184 Linux - Software 16 09-02-2010 12:05 PM
sed replace string octeto Programming 4 06-06-2007 03:09 AM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 11:58 AM
[sed] replace string? chuanyung Programming 3 03-11-2004 09:42 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:40 AM.

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