I need to check a string path ("C:/windows" for example) to see if the folder exists and if it doesn't then I need a value ret



Download 27 Kb.
Date17.12.2020
Size27 Kb.
#55045
Trim white spaces using awk

Trim white spaces using awk
Hi,

I have a CSV file with footer information as below. The third value is the number of records in the file. Sometimes it contains both leading and trailing white spaces which i want to trim using awk.

C,FOOTER , 00000642
C,FOOTER , 00000707
C, FOOTER, 42
C, FOOTER, 129
eval `awk -F, ' /FOOTER/ {print "set RecordsFound=" $3}

/HEADER/ { print "set FileBusinessDate=" $4} END{ print "set ActualRecords=" NR-2 } ' ${SourceDir}/${FileCsv} `


Above is the command which is already present in production and this statement fails since the $3 has spaces in it. So far we didn't get any spaces in the CSV, so this statement was working fine for the past 1 year.

Is there any way to trim the spaces(both leading and trailing spaces) in AWK?

I tried gsub(/ /,"",$3) but it doesn't work

Any help is much appreciated

Thanks in Advance


Mohana
‘-----------------------------------------------------------------------------------------------------------
Your statement is valid for one space, insert it in your AWK program :

Code:


/FOOTER/ {gsub(/ /,"",$3); print "set RecordsFound=" $3}

To suppress multiple spaces :

Code:

/FOOTER/ {gsub(/ */,"",$3); print "set RecordsFound=" $3}


Perhaps your field contains tabulation, modify the gsub statement :

Code:

/FOOTER/ {gsub(/[[:space:]]*/,"",$3); print "set RecordsFound=" $3}


jean-Pierre.






Download 27 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page