Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash error using the column command: 'column: line too long'

When I type this column command with my input file I get the following error

column -t text.txt > output
column: line too long
column: line too long
column: line too long
column: line too long
column: line too long
column: line too long

When I look at the file output it seems that the first half of the file(from left to right) is not printed.

Is there a way around this error? Is there a way to do exactly what the command would do otherwise without this error?


Sample input (Real input ~640 columns)

column1 column2 column3 column4
03  2   45  3
5   6   7   8

Sample output (Real output ~640 columns)

column1    column2  column3  column4
03         2        45       3
5          6        7        8
like image 998
Sam Avatar asked Jun 02 '17 22:06

Sam


2 Answers

You could try a naive awk implementation:

awk 'NR==FNR{for(i=1;i<=NF;i++) 
        max[i] = length($i) > max[i] ? length($i) : max[i]; next} 
{ for(i=1;i<=NF;i++) printf "%-"max[i]"s  ", $i; printf "\n"}' text.txt text.txt
like image 61
William Pursell Avatar answered Sep 22 '22 07:09

William Pursell


An alternative is to split the line into an array. This line is too long and column will not print it in full:

FULLTEXT=$(cat /Users/burroughclarke/Desktop/commaseperatedvalues.csv)
printf "$FULLTEXT" | column  -t -s ','

This prints it properly:

readarray -t ARR < <(cat /Users/burroughclarke/Desktop/commaseperatedvalues.csv | tr "\n" "\n") 
printf '%s\n' "${ARR[@]}" | column  -t -s ','
like image 20
Burrough Clarke Avatar answered Sep 22 '22 07:09

Burrough Clarke