The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 4
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' )
this finds "+myproject" but it also grabs the misc text. How do I get it to stop looking once it returns the project name. i.e. it should only return the "term" if it has the + sign in front.
Reply With Quote
Forum Sponsor
  #2  
Old 01-30-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
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
or
Code:
a=$( echo "+myproject 50 013107 misc text here maybe" | cut -d" " -f1 )
Reply With Quote
  #3  
Old 01-30-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
project=$( echo $input | sed 's/^\([^ ]*\).*/\1/g' )
Reply With Quote
  #4  
Old 01-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 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.
Reply With Quote
  #5  
Old 01-30-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
echo "76 +myproject 013107 mics text" | sed 's/^.*\(\+[^ ]*\).*/\1/g'
Reply With Quote
  #6  
Old 01-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 4
that's the one! Thanks. Can you possibly explain it?
Reply With Quote
  #7  
Old 01-30-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
echo "76 +myproject 013107 mics text" | sed 's/^.*\(\+[^ ]*\).*/\1/g'
\(\+[^ ]*\) this match string contains + and followed by any characters other than space.
.* matches any number of characters
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0