Link to home
Start Free TrialLog in
Avatar of morsa804tons
morsa804tons

asked on

sed/awk help

Hi, i've got a file composed of this kind of stuff:

python3         Solaris  zone  2G-05 colt zfs syslog-ng nemo env-testing-qa1 amadeusapi cachemanager
python4         Solaris  zone  1G-05 colt zfs syslog-ng nemo env-dev-qa1 apache2
python5         Solaris  zone  2G-30 colt zfs syslog-ng nemo env-dev-qa1 jboss
python6         Solaris  zone  2G-05 colt zfs syslog-ng nemo env-dev-qa1 amadeusapi cachemanager
python7         Solaris  zone  1G-05 colt zfs syslog-ng nemo env-testing-qa2 apache2
python8         Solaris  zone  2G-30 colt zfs syslog-ng nemo env-testing-qa2 jboss
python9         Solaris  zone  2G-05 colt zfs syslog-ng nemo env-testing-qa2 amadeusapi cachemanager
bergman1        Solaris  zone 17G-30 colt zfs syslog-ng nemo env-load-qa1 jboss

and i need to keep all words starting with env, but excluding "env-":

testing-qa1
dev-qa1
dev-qa1
...

How i can do that with sed or awk? (preferably sed)

Thanks!
Avatar of morsa804tons
morsa804tons

ASKER

i don't want to do it using cat file | awk '{ print $9 }', cause somebody can add new fields before my chosed text.
ASKER CERTIFIED SOLUTION
Avatar of Harisha M G
Harisha M G
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it works partially, because i've got a line like this:

depalma2        Solaris  zone  2G    colt zfs syslog-ng nemo env-master

it didn't keep env-master

but thx for your help!
Remove the space..

sed 's/.*env-\([^ ]*\).*/\1/' sample.txt > extract.txt

or

sed -i 's/.*env-\([^ ]*\).*/\1/' sample.txt

Open in new window

superb! thx!