LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 12-01-2015, 09:31 AM   #1
nab_elf
LQ Newbie
 
Registered: Aug 2013
Posts: 4

Rep: Reputation: Disabled
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
 
Old 12-01-2015, 10:29 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,687

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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?

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

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
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
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Linux Mint, Ubuntu
Posts: 1,506

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

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

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


Reply


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


All times are GMT -5. The time now is 08:34 AM.

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