LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 08:31 AM   #1
nab_elf
LQ Newbie
 
Registered: Aug 2013
Posts: 5

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, 09:29 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

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

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
RockDoctor
Senior Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu, Manjaro
Posts: 1,791

Rep: Reputation: 427Reputation: 427Reputation: 427Reputation: 427Reputation: 427
Something like this?
Code:
# echo '"@id": "45002"' | sed -e 's/["@]//g'  
id: 45002
 
Old 12-01-2015, 05:58 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 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
Open Source Consulting | Domain Registration