Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting problem

Status
Not open for further replies.

sumas

Programmer
Jul 9, 2006
9
US
2006|1152662407|coke|7|19:50:44|19:50:49|7.0000
2006|1152662407|coke|7|19:50:49|19:50:54|6.0000
2006|1152662407|coke|7|19:50:54|19:50:59|7.0000
2006|1152662407|coke|7|19:50:59|19:51:04|7.0000
2006|1152662407|coke|7|19:51:04|19:51:09|7.0000
2006|1152662407|coke|7|19:51:09|19:51:14|18.0000
2006|1152662407|coke|7|19:51:14|19:51:19|6.0000
2006|1152662407|coke|7|19:51:19|19:51:24|8.0000
2006|1152662407|coke|7|19:51:24|19:51:29|6.0000
2006|1152662407|coke|7|19:51:29|19:51:34|6.0000
2006|1152662407|coke|7|19:51:34|19:51:39|6.0000
2006|1152662407|coke|7|19:51:39|19:51:44|17.0000
2006|1152662407|coke|7|19:51:44|19:51:49|7.0000
2006|1152662407|coke|7|19:51:49|19:51:54|6.0000
2006|1152662407|coke|7|19:51:54|19:51:59|6.0000
2006|1152662407|coke|7|19:51:59|19:52:04|3.0000
2006|1152662407|coke|7|19:52:04|19:52:09|7.0000
2006|1152662407|coke|7|19:52:09|19:52:14|18.0000
2006|1152662407|coke|7|19:52:14|19:52:19|7.0000
2006|1152662407|coke|7|19:52:19|19:52:24|7.0000
2006|1152662407|coke|7|19:52:24|19:52:29|6.0000
2006|1152662407|coke|7|19:52:29|19:52:34|6.0000
2006|1152662407|coke|7|19:52:34|19:52:39|6.0000
2006|1152662407|coke|7|19:52:39|19:52:44|17.0000
2006|1152662407|coke|7|19:52:44|19:52:49|6.0000

I have the above file, I am using the script from one of the posts. I am trying to print the last column, which is
7.0000
6.0000
7.0000
7.0000
7.0000


BEGIN {
FS="|"
while (getline < "moo") {
NDC11[$2]=$5 ## Store Field 5 in ARRAY NDC11 using 2nd field as the subscript
}
}

#I don't know how to do it, so just hard-coded $1 == "F" here.
$1 == "F" && length(NDC11[$2])>0 {
print NDC11[$2], $8
}

Any help?

Thanks
 
Hi

In the above example all $2 are the same. So at the end you will have only one element in the array NDC11 containing th last row's $5.

You have Oonly 7 columns, so I do not understand why you print $8.

And I have definitely no idea what is the contition for those 5 lines which are printed out of 25, and why the other 20 are not.

If you shade some light on this misteries, you will get more/better/faster answers.

Feherke.
 
The script seems a little over complicated for just printing the last column.

For column 7 use:
awk -F"|" '{print $7}' /path/to/file

For the last column in unknown number of column (up to 199) use:
awk -F"|" '{print $NF}' /path/to/file

I hope that helps.

Mike
 
Thanks Mike. It works!!!! what would *.scr extension mean in awk and what would -F do exactly.I was using -f and it was not giving me right output.
 
what would *.scr extension mean in awk
nothing
what would -F do exactly
man awk
 
PHV that was very helpful!! Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top