The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
regex question xiamin Shell Programming and Scripting 3 03-05-2009 02:53 AM
Help with grep and regex raichlea UNIX for Dummies Questions & Answers 14 04-16-2008 11:25 AM
regex in variable alias47 UNIX for Dummies Questions & Answers 4 08-08-2007 08:37 AM
Regex deepakpv Shell Programming and Scripting 6 03-28-2007 04:18 AM
sed regex Shakey21 UNIX for Dummies Questions & Answers 4 01-31-2002 09:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-30-2007
lunac lunac is offline
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.
  #2 (permalink)  
Old 01-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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 )
  #3 (permalink)  
Old 01-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
project=$( echo $input | sed 's/^\([^ ]*\).*/\1/g' )
  #4 (permalink)  
Old 01-30-2007
lunac lunac is offline
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.
  #5 (permalink)  
Old 01-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

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

Join Date: Jan 2007
Posts: 4
that's the one! Thanks. Can you possibly explain it?
  #7 (permalink)  
Old 01-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0