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 |
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. |
nice one mate that has worked a treat :D
Marc |
sed -E '/^.*R000=(.*)\@.*/s//\1/';
;) |
perl -pi.bak -e 's/^.*?R000=(.*?)\@.*$/$1/' <file>
Makes the change in-place and backs up the file with a .bak extension :) |
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. |
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 ;)
|
Used to use REBOL to create static copies of dynamic web pages with URL rewriting, bizarre language.
|
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