Help answer threads with 0 replies.
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, 08:31 AM   #1
LQ Newbie
Registered: Aug 2013
Posts: 5

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, 09:29 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,270

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
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 09:37 AM.
Old 12-01-2015, 01:41 PM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
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, 03:23 PM   #4
Senior Member
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Linux Mint
Posts: 1,709

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

Rep: Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484Reputation: 2484
echo '"@id": "45002"'|sed -e 's/["a-z@]//g'
: 45002
Old 12-01-2015, 09: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 06: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 11:05 AM
sed replace string octeto Programming 4 06-06-2007 02:09 AM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
[sed] replace string? chuanyung Programming 3 03-11-2004 08:42 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:14 PM.

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