LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replace a string containing " with sed (https://www.linuxquestions.org/questions/linux-newbie-8/replace-a-string-containing-with-sed-4175560304/)

nab_elf 12-01-2015 08:31 AM

replace a string containing " with sed
 
Hello,
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


thank's
regards

berndbausch 12-01-2015 09:29 AM

A string containing " is expressed as
Code:

.*".*
but I doubt this is what you want.

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

grail 12-01-2015 01:41 PM

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 :)

RockDoctor 12-01-2015 03:23 PM

Something like this?
Code:

# echo '"@id": "45002"' | sed -e 's/["@]//g' 
id: 45002


chrism01 12-01-2015 05:58 PM

Code:

echo '"@id": "45002"'|sed -e 's/["a-z@]//g'
: 45002


Aia 12-01-2015 09:40 PM

Code:

echo '"@id": "45002"' | sed 's/"\|@\|id//g'
Code:

: 45002


All times are GMT -5. The time now is 07:13 AM.