I am using awk in a bash script and do something like:
awk -F, -v result_file=$2'{
print $2 $1 > result_file
}' $data_file
In the output file, I am getting a control-M '^M' character at end of each line. What is wrong?
Using Awk command We can use the built-in functions length and substr of awk command to delete the last character in a text.
txt. If you notice awk 'print $1' prints first word of each line. If you use $3, it will print 3rd word of each line.
awk '{ print $2; }' prints the second field of each line. This field happens to be the process ID from the ps aux output.
awk '{print $9}' the last ls -l column including any spaces in the file name.
The record separator is automatically set to the line-ending of the current system, LF (\n
) on the Unix-based systems, CR-LF (\r\n
) on MS systems and CR (\r
) on Mac OS prior to Mac OS X. So to work on a file recorded on an MS system set the record separator appropriately, in your case:
awk -v RS='\r\n' ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With