Cvg
June 12, 2013, 6:38am
1
Hi all,
I have the below line:
08 03 * * 1-5 XXXXXXXXXXXXX -ENVI LDNFOUAT10 -EXE xxxxxxxx -CONFIG \${xxxxx} -SUBCLASS RESET -START -EXTRAAPPARGS \" -env 38LDNFOUAT10 \" >> /tmp/SRRC_xxxxxxx_start.log.`/usr/bin/date +\%Y\%m\%d` 2>&1
I want to print just one word after the string "-env", in this case the output would be 38LDNFOUAT10.
Sorry if this has been asked before, I've been googling and all I can do is print the line AFTER the match.
Jotne
June 12, 2013, 6:47am
2
Please use code tags
awk -F"-env " '{split($2,a," ");print a[1]}' file
38LDNFOUAT10
This solution was posted just a few post before yours:
Use some time to read forum before post.
echo '08 03 * * 1-5 XXXXXXXXXXXXX -ENVI LDNFOUAT10 -EXE xxxxxxxx -CONFIG \${xxxxx} -SUBCLASS RESET -START -EXTRAAPPARGS \" -env 38LDNFOUAT10 \" >> /tmp/SRRC_xxxxxxx_start.log.`/usr/bin/date +\%Y\%m\%d` 2>&1' | awk -F"-env" '{split($2,a," "); print a[1]}'
Cvg
June 12, 2013, 7:28am
4
That's odd, if I run the command you guys provided in my host (I'm using Cygwin) it works, however if I run it in a Solaris machine i'm getting a different output:
echo '08 03 * * 1-5 XXXXXXXXXXXXX -ENVI LDNFOUAT10 -EXE xxxxxxxx -CONFIG \${xxxxx} -SUBCLASS RESET -START -EXTRAAPPARGS \" -env 38LDNFOUAT10 \" >> /tmp/SRRC_xxxxxxx_start.log.`/usr/bin/date +\%Y\%m\%d` 2>&1' | awk -F"-env" '{split($2,a," "); print a[1]}'
5
What could be the reason?
---------- Post updated at 01:28 PM ---------- Previous update was at 01:25 PM ----------
Jotne, I've spent the morning searching in this and other forums and couldn't find what I was looking for. Thanks for the link though.
Hi! In an awk tutorial i was reading (from www.grymoire.com), it was mentioned that i can set the input field separator to more than one character using FS. However when i tried it out, it wasnt worki | The UNIX and Linux Forums
you could use nawk instead of awk
1 Like
Jotne
June 12, 2013, 7:31am
6
Not sure why its not working, its ok on my ubuntu.
Maybe some of the other here nows?
Edit: after reading post from rajamadhavan, try
awk -F'-env' '{split($2,a," "); print a[1]}'
or
awk '{split($2,a," "); print a[1]}' FS="-env"
awk '{split($2,a," "); print a[1]}' FS='-env'
1 Like
Try using nawk instead of awk.
Seems like the Solaris awk is accepting only a single-character FS.
1 Like
Cvg
June 12, 2013, 12:00pm
8
Yes I tried nawk instead and it works, thanks for your help.