![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with grep and regex | raichlea | UNIX for Dummies Questions & Answers | 14 | 04-16-2008 08:25 AM |
| regex in variable | alias47 | UNIX for Dummies Questions & Answers | 4 | 08-08-2007 05:37 AM |
| regex question | xiamin | Shell Programming and Scripting | 2 | 07-16-2007 04:40 AM |
| Regex | deepakpv | Shell Programming and Scripting | 6 | 03-28-2007 01:18 AM |
| sed regex | Shakey21 | UNIX for Dummies Questions & Answers | 4 | 01-31-2002 06:16 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Regex?? Please help
Ok, this has got to be simple, but I can't wrap my head around it.
I'm trying to divid up different parts of a line being inputted. The reason is so I don't have to worry about what order the information is place, I can sort it before it's added to my file. the line would look something like this +myproject 50 013107 misc text here maybe I need each piece to be found and placed in it's variable -- then some other actions maybe added to it. Anyway, I started the first "+myproject" Code:
project=$( echo $input | sed 's/[^\+[:alpha:]]//g' ) |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
echo "+myproject 50 013107 misc text here maybe" | while read a b c d e f g do echo $a $b $c $d $e $f $g done Code:
a=$( echo "+myproject 50 013107 misc text here maybe" | cut -d" " -f1 ) |
|
#3
|
|||
|
|||
|
Code:
project=$( echo $input | sed 's/^\([^ ]*\).*/\1/g' ) |
|
#4
|
|||
|
|||
|
Those solutions only work if "+myproject" is the first item entered. But what if a user put in
76 +myproject 013107 mics text I need to be able to find "+myproject" in the string where ever it is and return only that. |
|
#5
|
|||
|
|||
|
Code:
echo "76 +myproject 013107 mics text" | sed 's/^.*\(\+[^ ]*\).*/\1/g' |
|
#6
|
|||
|
|||
|
that's the one! Thanks. Can you possibly explain it?
|
|
#7
|
|||
|
|||
|
Code:
echo "76 +myproject 013107 mics text" | sed 's/^.*\(\+[^ ]*\).*/\1/g' .* matches any number of characters |
|||
| Google The UNIX and Linux Forums |