It seems that only one column will exist in any given csv, I have yet to find a csv where both columns exist.
I want an output, sent to another csv, that tells me if the script found either column and where that column was found i.e. field/column-number of that field. For the other, 'missing', column I want the script to output a suitable message in the appropriate cell of the output csv.
I have written some versions of the script that work, more complicated than the one of this post, but I am wondering what is wrong with this script?
Code: Select all
file1=$(date "+1_Flightlog_summary_%Y-%m-%d_[%H-%M-%S].csv")
file2=$(date "+2_set_max_height_all_hopefully_%Y-%m-%d_[%H-%M-%S].csv")
gawk -F, '{if(NR ==1){
print "a ,FILENAME ,FNR ,NR ,a ,set_max_height_col_label ,set_max_height_col_nos ,a ,max_height_status ,status_clo_nos ,a ,activation_date ,activ_date_col_nos" > ("output/set_max_height_all_hopefully.csv")
print " " >> ("output/set_max_height_all_hopefully.csv")
}
if (FNR ==1) {Limit=0 ;status=0 ;act_date=0 ;cCol_titles_found=0 }
if ((FNR <=2) && (cCol_titles_found <1) && ($1 !~/sep/) && ($1 !="")) { cCol_titles_found++
for (i=1; i<=NF; i++){if (($i ~/HOME.heightLimit/) && ($i !~/HOME.heightLimitStatus/)) {Limit = i }
if (($i ~/HOME.heightLimitStatus/) || ($i ~/HOME.isReachedLimitHeight/)) {status = i }
if (($i ~/RECOVER.activeTimestamp/)|| ($i ~/DETAILS.activeTimestamp/)) {act_date = i }
}
if (Limit ==0) {$(Limit) =1}
if (status ==0) {$(status) =2}
if (act_date ==0) {$(act_date) =3}
print " c,"FILENAME","FNR","NR", c ,"$(Limit)","Limit", c ,"$(status)","status", c ,"$(act_date)","act_date >> ("output/set_max_height_all_hopefully.csv")
# close ------------------------------------------------------------------------------------(FNR <=2) && ......
}
}' *.csv > output/$file1
pwd
mv output/set_max_height_all_hopefully.csv output/$file2
rm output/1*.csv
The script has oddities left over from the bigger script from which was taken i.e. "Col_titles_found" and "cshl" but I do not think they cause a problem
The output of the above is shown in the second attached. The first attachment shows the output of one of the other versions which is getting closer to what I want.
Thanks for any assistance
PS as far as I can see from the tests I have made the MODIFIED script works correctly up to the point where the "for (i=1; i<=NF; i++)" loop is closed, I get the correct data in the output csv if I have print statements immediately after the close of the "for i" loop that do not use "$(Limit)" and "$(status) where $(Limit) & $(status) would equate to $0.
I CAN NOT see what is wrong the the following 4 lines
Code: Select all
if (Limit ==0) {$(Limit) =1}
if (status ==0) {$(status) =2}
if (act_date ==0) {$(act_date) =3}
print " c,"FILENAME","FNR","NR", c ,"$(Limit)","Limit", c ,"$(status)","status", c ,"$(act_date)","act_date >> ("output/set_max_height_all_hopefully.csv")
PPS I added the search for the third column "activeTimeStamp" just to see if the problem was due to "HOME.heightLimit" being a subset of "HOME.heightLimitStatus" but the output for $(act_date) is screwed up too.