0

I have an awk command piped to the output of another command | awk {'print $2,$3'}. When I run this command the output displays the data in columns, of the columns as I would expect

column2 column3
a       a
b       b
c       c

no problems there, but when I add this output to a script and sent it to >> $log the data is not formatted in columns... just normal line text

column 2 output, column 3 output, column 4 output...etc.

This isn't really a problem but would be easier to deal with down the road in the column format. what do I need to change in the script log output to format it in columns?

Here is the command as it is in the script

d=$(COMMAND| awk {'print $2,$3'})

Then sent to the log here

echo $d >> $log
mcv110
  • 13
  • 1
    Can you show exactly how you use the awk program in the script, by adding a (possibly anonymized) excerpt from the script? In particular quoting and the like could be an issue here. – AdminBee Sep 23 '21 at 15:14
  • 1
    Can you provide a working example of the problem? (Sample data file, relevant awk command, and expected vs actual output.) I don't see why the awk command in your question would do that. – Chris Davies Sep 23 '21 at 15:15
  • added as an edit – mcv110 Sep 23 '21 at 15:20
  • In most shells, you need to quote "$d" to prevent word splitting. See New line in bash variables – steeldriver Sep 23 '21 at 15:33
  • I will take a look at that. does it matter that this is ash ?- BusyBox v1.17.1 built-in shell (ash) I do have other variables called in the same manner...that is without the quotes, but none require formatting like this. I will give that a try. thanks – mcv110 Sep 23 '21 at 15:40
  • that did it. the "$d" worked like a charm. how do I mark this as the answer? thanks for the input – mcv110 Sep 23 '21 at 15:43
  • 1
    Regarding {'print $2,$3'} - where did you get the idea to put the script delimiters (') inside the script instead of around the script '{print $2,$3}'? I've seen enough people do that that I feel like some tutorial or something somewhere is telling people to do it and I'd love to know where that is to correct the author. – Ed Morton Sep 23 '21 at 16:07
  • I didnt realize that was a delimiter. I thought it was part of the command syntax. other than being not correct, what is the difference? I see no change in output regardless of where the ' sits. not trying to be snarky here btw...genuinely curious. I am not a software person at all...AT ALL. so this is new knowledge to me. I think I read it in a forum post somewhere but would have to dig it out – mcv110 Sep 23 '21 at 16:57

0 Answers0