awk - How to get a field by counting the column ( number of character) -
awk - How to get a field by counting the column ( number of character) -
i have logfile.txt
, want specify filed $4 based on number of column not number of field because fields separated spaces characters , field 2 ($2
) may contain values separated space. want count lines don't know how specify $4
without causing problem if field 2 ($2
) contain space character.
here file:
kjkjj1kljkjkj928482711 piejhhkia 87166188177633 ajhhhh77760 00666667 876876800874 2014100898798789979879877770 kjkjj1kljkjkj928482711 hkhg 81882776553868 hghaljlka700 00876763 216897879879 2014100898798789979879877770 kjkjj1kljkjkj928482711 uut uggt 81762665356426 hgjhghjg661557008 00778787 268767860704 2014100898798789979879877770 kjkjj1kljkjkj9284827kj arth hgg 08276255534867 hgjhghjg661557008 00876767 212668767684 2014100898798789979879877770
here code :
awk 'end { ofs="\t"; (k in c) print c[k],"\t"k,"\t"f[k] } { k = $4 c[k]++; f[k]=substr($0,137,8) }' logfile.txt
i want count based on field $4. specify field in code must based on number of character (substr ($0,..,..) :
the output shold :
1 20141008 ajhhhh77760 1 20141008 hghaljlka700 2 20141008 hgjhghjg661557008
if records composed of fixed width fields can utilize cut(1)
% cutting -c1-22,23-42,43-62,... --output-delimiter=, file | sed 's/, */,/g' > file.csv % awk -f, '{your_code}' file.csv
please write range each of fixed width fields, in place of ...
ellipsis. have written ranges first three, lazy me.
if don't want bother intermediate file, utilize |
pipe.
awk
Comments
Post a Comment