I have a simple awk command that converts a date from MM / DD / YYYY to YYYY / MM / DD. However, the file I'm using has \ r \ n at the end of the lines, and sometimes the date is at the end of the line.
awk '
BEGIN { FS = OFS = "|" }
{
split($27, date, /\//)
$27 = date[3] "/" date[1] "/" date[2]
print $0
}
' file.txt
In this case, if the date MM/DD/YYYY\r\n, then I get this as a result:
YYYY
/MM/DD
What is the best way to get around this? Keep in mind, sometimes input is simple \r\n, in which case the output MUST be //, but instead ends up like
/
/
source
share