awk append string
Hi,
I'm trying to add a string after this AWK result: $ awk '/H005/ {print $0;}' 010.txt |H005|31032015|42498804,50|01| I'm trying this way: $ awk '/H005/ {print $0, "test";}' 010.txt But AWK is printing the string before the result and overwriting the first and second column: $ awk '/H005/ {print $0, "test";}' 010.txt test|31032015|42498804,50|01| how could i append the STRING to the end of the result ? |H005|31032015|42498804,50|01|test |
I strongly suspect that the source file has DOS line endings and the last character of the line is a carriage return. That will make it appear that your string is replacing the start of the line, whereas in fact it is not. You need to run the dos2unix utility on the file to convert the line endings, or else filter out the carriage return in the awk script.
Code:
awk '/\r$/ {gsub("\\r$", "")} /H005/ {print $0 "test"}' |
Quote:
You are right, the file was created on windows. The script worked perfectly, thank you ! |
All times are GMT -5. The time now is 05:14 PM. |