Previously I was using kali linux to code my bash file so it has no issue with the command, but after since I use ubuntu I realized it does not work on ubuntu and can’t find any solution to this problem yet.
Ori Code
tr ':' 't' < venue.txt | tr ' ' '_____" | awk -F "t '$1=Name {print $2,$3,$4,$5,$6}' Name=$Name | column -t --table-columns "Number:", "Type:", "Capacity:" , "Status:" | tr '_____' ' '
venue.txt
B:B01:Random:6:This is a long message
C:C01:Lab:5:This is message
I wanted the output be something like this, without the use of column –table-columns since somehow ubuntu does not support it, best would be awk
(When name==b, output be like)
Number Type Capacity Status
B01 Random 6 This is a long message
2
Answers
Somehow managed doing it after using this
Your code:
tr
is not needed;awk
has-F
tr
command has a double-quote ("
) where there should be a single-quote, so the entire command meaning changes (theawk
command becomes extra arguments totr
– which would give a syntax error). Was this a typo fortr ' ' '_____'
?tr 'x' 'yyyyy'
==tr 'x' 'y'
awk -F "t '...
a typo forawk -F 't' '...
?$1=Name
assigns the value of variableName
to the first field. Perhaps you intended to compare (==
) ?$6
will always be empty sincevenue.txt
has only 5 fieldstr 'xxxxx' 'y'
==tr 'xxxxx' 'yyyyy'
==tr 'x' 'y'
If you are trying to print the record in
venue.txt
whose first column equals the value of bash variableName
, without printing the name itself, and converting the:
delimiter to a tab and adding a header line to the output, you can do everything with a singleawk
command:It would not be hard to use
awk
to align the columns but it needs two passes and is more effort than usingcolumn
: