LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-08-2011, 04:23 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
sed regex get multiple string match in array?


Hi, I have a sed match that matches for certain string of a regex expression:
Code:
tname=$(echo "$contents" | sed -n 'some pattern')
How do I match for multiple strings in the $contents and return them as an array?
for example
Code:
contents="this is a text, just to match patterns, here is another text to be matched"
the sed func would be able to recognize both "text"s, but only one is outputted?
Possible to put it in an array? so ${bar[0]} gives one and ${bar[1]} gives another
Thanks,
Ted

Last edited by ted_chou12; 04-08-2011 at 04:48 PM.
 
Old 04-08-2011, 05:07 PM   #2
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
Hi, I have found \0 actually returns the whole match, but not as a variable, I think it might be close to what I wish, but not yet there:
Code:
#original
tname="$(echo "$content" | sed -n '/Content-Disposition/{ /".*"/!N}
			/Content-Disposition/{ /".*"/!N}
			/Content-Disposition/{ /".*"/s/\n//g;s/.*"\(.*\)"/\1/p}')"
#new
tname="$(echo "$content" | sed -n '/Content-Disposition/{ /".*"/!N}
			/Content-Disposition/{ /".*"/!N}
			/Content-Disposition/{ /".*"/s/\n//g;s/.*"\(.*\)"/\0/p}')"
this would actually give:
Code:
|Content-Disposition: attachment;       filename="=?big5?B?QXJhc2hpILRQLUxvdHVzLnRvcnJlbnQ=?="
Content-Disposition: attachment;        filename="[CASO][Freezing][01-12][GB][RV10].torrent"|
give the whole result, but I only want what's in the quotation, and I want it in arrays rather than as a whole string.(shown by the pipes)
Thanks,
Ted

Last edited by ted_chou12; 04-08-2011 at 05:08 PM.
 
Old 04-09-2011, 02:09 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,562

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
You marked this as SOLVED .. is that correct?
 
Old 04-09-2011, 03:16 AM   #4
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
yes, sorry, I solved it!
Ted
 
  


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
output the occurence number in sed or grep results in every regex match mbaste2 Linux - General 3 04-06-2011 01:58 AM
Help with sed regex to match words via a pattern. logar0 Linux - Newbie 3 10-24-2010 04:33 PM
sed remove string until final match Guyverix Linux - Newbie 6 03-20-2010 06:32 AM
[SOLVED] regex match string from start to find unique combinations fukawi2 Programming 6 02-11-2010 05:32 PM
Sed and regex: how to replace up to a certain string olliesa Linux - General 2 10-21-2009 02:49 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration