0

a (hopefully) simple question, I have a text output (coming from grep) that looks like this:

2241,"{87177540-CA46-4356-84A3-32C1F16E57F9}","THEFERRY2","15-20m.","50-100cm","Mature",643,"Ulmus procera","English elm","NBNSYS0000003812",346760,730607,56.4645790890058,-2.86562748812157
2273,"{0D6C7ECE-D834-453E-A08C-E9B0AFB9490A}","THEFERRY4","10-15m.","25-50cm","Mature",643,"Ulmus procera","English elm","NBNSYS0000003812",346733,730589,56.4644143392449,-2.8660619300834

and I am piping it into this awk command:

awk 'BEGIN {FS=","} { print $13 $14 $4 $5 $6 }'

and getting the following output

"15-20m.""50-100cm""Mature"812157
"10-15m.""25-50cm""Mature"300834

I expect to get the 5 desired columns printed but I have no idea what it is doing instead.

Appreciate any help.

  • Your file has CRLF line breaks. Use `dos2unix` to remove the CR characters. – Barmar Nov 10 '21 at 19:52
  • `grep ... | dos2unix | awk ...` – Cyrus Nov 10 '21 at 19:54
  • 1
    You need not use `grep` with `awk` but you have shown only `awk` command in your question so you could use like: `your_grep_command | awk 'BEGIN {FS=","} { sub(/\r$/,"");print $13 $14 $4 $5 $6 }'` OR to remove all control M use following: `your_grep_command | awk 'BEGIN {FS=","} {gsub(/\r/,"");print $13 $14 $4 $5 $6 }'`. Attached link in question has many ways of removing control M chars also to understand it better. – RavinderSingh13 Nov 10 '21 at 19:59
  • Or add `RS="\n|\r\n"` to your BEGIN rule. – Cyrus Nov 10 '21 at 20:04
  • 1
    @Cyrus `RS="\n|\r\n"` = `RS="\r?\n"` but either way that requires GNU awk for multi-char RS. – Ed Morton Nov 11 '21 at 17:05
  • @Ben all of the answers in the question that yours was closed as a dup of are wrong. See [why-does-my-tool-output-overwrite-itself-and-how-do-i-fix-it](https://stackoverflow.com/questions/45772525/why-does-my-tool-output-overwrite-itself-and-how-do-i-fix-it) for the right solutions. – Ed Morton Nov 11 '21 at 17:06

0 Answers0