ScoobyNet.com - Subaru Enthusiast Forum

ScoobyNet.com - Subaru Enthusiast Forum (https://www.scoobynet.com/)
-   Computer & Technology Related (https://www.scoobynet.com/computer-and-technology-related-34/)
-   -   Unix Script Help (https://www.scoobynet.com/computer-and-technology-related-34/251322-unix-script-help.html)

marcmann 17 September 2003 08:53 AM

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

richrussell 17 September 2003 09:09 AM

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.

marcmann 17 September 2003 09:16 AM

nice one mate that has worked a treat :D

Marc

Andrewza 17 September 2003 02:10 PM

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

;)

stevencotton 17 September 2003 02:21 PM

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

Makes the change in-place and backs up the file with a .bak extension :)

richrussell 17 September 2003 02:34 PM

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.

stevencotton 17 September 2003 02:38 PM

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 ;)

Andrewza 17 September 2003 04:28 PM

Used to use REBOL to create static copies of dynamic web pages with URL rewriting, bizarre language.

stevencotton 17 September 2003 04:49 PM

Cool. Did you choose it or was it something already in use?


All times are GMT +1. The time now is 05:09 PM.


© 2024 MH Sub I, LLC dba Internet Brands