1745813 Members
4011 Online
108722 Solutions
New Discussion юеВ

Help needed in awk

 
SOLVED
Go to solution
Rahul_13
Advisor

Help needed in awk

Hi,

I have few log files like:

handler_5620_15:09:48.log
handler_566_14:31:07.log
handler_7995_15:28:39.log

and more...

I have to extract the portion till the second underscore (till handler_5620) for all the logs. I know how to accomplish this in SHELL script. But I have to do this using AWK.

Can anyone please help me out in this problem.

Thanks,
Rahul
3 REPLIES 3
Mark Greene_1
Honored Contributor
Solution

Re: Help needed in awk

try this:

awk 'BEGIN { FS = "_"}; { print $1, $2 }' [filenamehere]


mark
the future will be a lot like now, only later
Jean-Luc Oudart
Honored Contributor

Re: Help needed in awk

or

awk -F"_" '{print$1,$2;}'
Rgds
JL
fiat lux
Stuart Abramson_2
Honored Contributor

Re: Help needed in awk

ls -1 | while read FN
do
echo $FN | awk -F_ '{print $1 "_" $2}'
done

will put the "_" back in the ouptput string..