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
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:14awk
command, and expected vs actual output.) I don't see why theawk
command in your question would do that. – Chris Davies Sep 23 '21 at 15:15"$d"
to prevent word splitting. See New line in bash variables – steeldriver Sep 23 '21 at 15:33ash
?-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"$d"
worked like a charm. how do I mark this as the answer? thanks for the input – mcv110 Sep 23 '21 at 15:43{'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