![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to parse a string efficiently | sandiego_coder | Shell Programming and Scripting | 4 | 05-13-2008 09:12 AM |
| how to parse this string | hcliff | Shell Programming and Scripting | 13 | 04-02-2008 01:43 AM |
| Parse String in XML file | racbern | Shell Programming and Scripting | 4 | 12-19-2007 08:26 AM |
| String parse question | mnreferee | Shell Programming and Scripting | 5 | 03-06-2007 08:30 PM |
| parse a string variable | methos | Shell Programming and Scripting | 3 | 10-18-2005 01:18 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Parse String Using Sed
Hi,
I am wondering if there's a simpler way to extract the second occurrence of a word enclosed in [ ] that matches my search criteria. Sample Input is as follows: HTML Code:
[main] Error installing feature [fmx] - com.er.nms.cif.ist.NoMatchingUpgra [main] Error installing feature [fmav] - com.er.nms.cif.ist.NoMatchingUpgra HTML Code:
fmx fmav Here's my code: Code:
while read data; do echo $data | sed -e 's/\([.[a-z]*] \)//' | sed 's/[A-Za-z ]*//' | sed 's/-.*//' | sed 's/]//' | sed 's/\[//' done < data.txt //racbern |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
sed -e 's/.*\].*\[//' -e 's/\].*//' data.txt As a side remark, you should always double quote any variables. |