kcdg859
December 26, 2014, 5:33am
1
hi,
i have a fixed width file with multiple columns and need to print data using awk command.
i use:
awk -F "|" '($5 == BH) {print $1,$2,$3}' <non_AIM target>.txt
for a delimiter file.
but now i have a fixed width file like below:
7518 8269511BH 20141224951050N8262
11148 8269511BH 20141224951050N8262
11718 8269511BH 20141224951050N8262
Fixed width column wise lengths: 7,3,3,1,2,11,8,3,3,1,3,1
Could u pls help me to fetch data for rows with col5 as 'BH' value
I am new to awk coomands.
Appreciate ur help in advance
1 Like
Try GNU awk:
awk '$5=="BH"' FIELDWIDTHS="7 3 3 1 2 11 8 3 3 1 3 1" file
or regular awk:
awk 'substr($0,15,2)=="BH"'
or
sed '/^.\{14\}BH/!d' file
1 Like
kcdg859
December 26, 2014, 5:55am
3
What is i have to fetch only particular columns like $1,$2 with an extra condition like $5='BH' and $1=7518
Thanks for your quick reply.
Try (GNU awk) :
awk '$5=="BH" && $1==7518{print $1, $2}' FIELDWIDTHS="7 3 3 1 2 11 8 3 3 1 3 1" file
1 Like
RudiC
December 26, 2014, 3:01pm
5
Might also be of some interest:
awk '$15$16=="BH" && $1$2$3$4=="7518" {print $1$2$3$4$5$6$7$8$9$10}' FS="" file4
7518 826
Note: an empty FS to make each individual character a separate field is supported by GNU awk, mawk and BSD awk, but it is not POSIX-compliant and therefore not universally supported..
1 Like