gio001
April 26, 2010, 11:28am
1
Hello everyone,
can anyone please help?
I have this generic line from a cron file saved into a file named testInput:
12 8-17,1 * * 1-5 /myroot/TEST/bin/testJob.ksh TEST 1>/myroot/TEST/logs/testJob.log 2>1
when I use awk to get the second field I only get 8-17.
I even tried to force the separator to be a space, yet it only returns 8-17 while I would expect 8-17,1 .
Here is the line ....
awk 'BEGIN { FS = " " };{printf(" %s",$2)}' testInput
Can you tell me what am I doing wrong?
Thanks.
zaxxon
April 26, 2010, 11:37am
2
A
awk '{print $2}' testInput
should be totally sufficient.
Do you have another box with another version of awk maybe where could try this line?
Default awk FS is any number of spaces (blanks and tabs). Strange behaviour in my eyes.
It works properly on my machine, I got "8-17,1".
panyam
April 26, 2010, 11:39am
4
Surprising,
for me it's working fine:
TESTBOX>cat i_file
12 8-17,1 * * 1-5 /myroot/TEST/bin/testJob.ksh TEST 1>/myroot/TEST/logs/testJob.log 2>1
TESTBOX>awk '{ print $2 }' i_file
8-17,1
masta
April 26, 2010, 11:42am
5
I see a possible problem.
The asterisk symbols on input might be evaluated in awk as an expression.
cat testInput | awk -F' ' '{printf(" %s",$2)}'
8-17,113
See how two ones' (11) came together, and those were separated by two asterisk symbols.
gio001
April 26, 2010, 11:50am
6
Everything now works ..... there was a probelm with my data file ......
Thanks again!
panyam
April 26, 2010, 12:02pm
7
masta:
I see a possible problem.
The asterisk symbols on input might be evaluated in awk as an expression.
cat testInput | awk -F' ' '{printf(" %s",$2)}'
8-17,113
See how two ones' (11) came together, and those were separated by two asterisk symbols.
I don't think so , from where you got "3" in your output then?..
$ awk '{print $2}' k.txt
8-17,1
$