Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Unix Script Help

Thread Tools
 
Search this Thread
 
Old 17 September 2003, 08:53 AM
  #1  
marcmann
Scooby Regular
Thread Starter
 
marcmann's Avatar
 
Join Date: Oct 2002
Posts: 163
Likes: 0
Received 0 Likes on 0 Posts
Post

Hi,

Trying to use SED with no luck.

I have a line in a file:

E=23=2003082163229=5.0#509=R000=MannMa@COSINC32341 2=

I want to extract from this line the MannMa part only - however this part will change depending on user so it isn't constant. The R000= before it is though if this is any help. I've played around with SED but can't get it to work. Any ideas?

Cheers

Marc
Old 17 September 2003, 09:09 AM
  #2  
richrussell
Scooby Regular
 
richrussell's Avatar
 
Join Date: May 2003
Posts: 114
Likes: 0
Received 0 Likes on 0 Posts
Post

You might have been better off using awk, but anyway, with sed, it's not too hard. There's probably a more elegant way, but this took me 30 seconds to come up with:

(assuming your list of strings is in a file called 'input')

$ cat input | sed 's/^.*=R000=//' | sed 's/@.*$//'

^.* matches everything from the beginning of the line (so up to and including the =R000= in this case)
.*$ matches everything to the end of the line (so everything including and after the @)

Rich.
Old 17 September 2003, 09:16 AM
  #3  
marcmann
Scooby Regular
Thread Starter
 
marcmann's Avatar
 
Join Date: Oct 2002
Posts: 163
Likes: 0
Received 0 Likes on 0 Posts
Post

nice one mate that has worked a treat

Marc
Old 17 September 2003, 02:10 PM
  #4  
Andrewza
Scooby Regular
 
Andrewza's Avatar
 
Join Date: Jan 2002
Posts: 667
Likes: 0
Received 0 Likes on 0 Posts
Post

sed -E '/^.*R000=(.*)\@.*/s//\1/';

Old 17 September 2003, 02:21 PM
  #5  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

perl -pi.bak -e 's/^.*?R000=(.*?)\@.*$/$1/' <file>

Makes the change in-place and backs up the file with a .bak extension
Old 17 September 2003, 02:34 PM
  #6  
richrussell
Scooby Regular
 
richrussell's Avatar
 
Join Date: May 2003
Posts: 114
Likes: 0
Received 0 Likes on 0 Posts
Post

I knew there were more elegant ways - but I did only spend 30 seconds on it whilst drinking my morning cup of tea!

Perl's overkill for this, sed/awk are plenty sufficient.

Rich.
Old 17 September 2003, 02:38 PM
  #7  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

I hoped more people would jump in with ever more overkill ways to do it. First person to give a REBOL solution will have my admiration

Trending Topics

Old 17 September 2003, 04:28 PM
  #8  
Andrewza
Scooby Regular
 
Andrewza's Avatar
 
Join Date: Jan 2002
Posts: 667
Likes: 0
Received 0 Likes on 0 Posts
Post

Used to use REBOL to create static copies of dynamic web pages with URL rewriting, bizarre language.
Old 17 September 2003, 04:49 PM
  #9  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

Cool. Did you choose it or was it something already in use?
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
SD
Computer & Technology Related
6
24 April 2002 03:35 PM
SD
Computer & Technology Related
5
24 April 2002 10:29 AM
Karlos
Computer & Technology Related
9
10 March 2002 03:23 PM
Blackscooby
Computer & Technology Related
3
01 March 2002 09:25 AM



Quick Reply: Unix Script Help



All times are GMT +1. The time now is 11:16 PM.