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

Old Sep 17, 2003 | 08:53 AM
  #1  
marcmann's Avatar
marcmann
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 163
Likes: 0
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
Reply
Old Sep 17, 2003 | 09:09 AM
  #2  
richrussell's Avatar
richrussell
Scooby Regular
 
Joined: May 2003
Posts: 114
Likes: 0
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.
Reply
Old Sep 17, 2003 | 09:16 AM
  #3  
marcmann's Avatar
marcmann
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 163
Likes: 0
Post

nice one mate that has worked a treat

Marc
Reply
Old Sep 17, 2003 | 02:10 PM
  #4  
Andrewza's Avatar
Andrewza
Scooby Regular
 
Joined: Jan 2002
Posts: 667
Likes: 0
Post

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

Reply
Old Sep 17, 2003 | 02:21 PM
  #5  
stevencotton's Avatar
stevencotton
Scooby Regular
 
Joined: Jan 2001
Posts: 2,710
Likes: 1
From: behind twin turbos
Post

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

Makes the change in-place and backs up the file with a .bak extension
Reply
Old Sep 17, 2003 | 02:34 PM
  #6  
richrussell's Avatar
richrussell
Scooby Regular
 
Joined: May 2003
Posts: 114
Likes: 0
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.
Reply
Old Sep 17, 2003 | 02:38 PM
  #7  
stevencotton's Avatar
stevencotton
Scooby Regular
 
Joined: Jan 2001
Posts: 2,710
Likes: 1
From: behind twin turbos
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
Reply
Old Sep 17, 2003 | 04:28 PM
  #8  
Andrewza's Avatar
Andrewza
Scooby Regular
 
Joined: Jan 2002
Posts: 667
Likes: 0
Post

Used to use REBOL to create static copies of dynamic web pages with URL rewriting, bizarre language.
Reply
Old Sep 17, 2003 | 04:49 PM
  #9  
stevencotton's Avatar
stevencotton
Scooby Regular
 
Joined: Jan 2001
Posts: 2,710
Likes: 1
From: behind twin turbos
Post

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


Thread Tools
Search this Thread

All times are GMT +1. The time now is 03:47 AM.