Greetings.
I have files that contains eleven fields in the file name. Each file has a specific meaning. My job is to list each file name and load the info into a database table for reporting.
My awk code does this (files have VER suffix):
find . -name "*.VER" -exec ls '{}' ';' -printf %f\\t | awk -F"~" '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$0}' > somefile.tab
It works fine except that it does something weird with the file name ($0): it repeats it like so (the 2 last fields from the right):
RRR1 PRE DTV_PREP PREP05 JGM15453. 26 P H23-600 029416589165 20110216 RRR1~PRE~DTV_PREP~PREP05~JGM15453.~26~P~H23-600~029416589165~20110216~090353.VER ./RRR1~PRE~DTV_PREP~PREP05~JGMDTV269~33~P~H21-200~029384120357~20110216~091829.VER
If I remove “%f” switch from the printf statement, it seems to work but if I leave it alone and remove $0, file name never gets displayed. What am missing here? Any ideas?
Thanks for your input.
awkisn’t printing it out twice,findis due to thelsand the-printf. I don’t see the reason for the-exec ls '{}' ';'anyway. You should be able to simply remove it like so:By the way, you can greatly simplify you code like so:
Note that you were missing the 11th field
$11in your code. Both my answers will print this out.