Tag Info

New answers tagged

1

If I understand your question correctly, this will do what you want: awk -F, 'NR!=1 { if (max_NF < NF) max_NF = NF; for (i=1; i<=NF; i++) if (max[i] < length($i)) max[i] = length($i) } END { for (i=1; i<=max_NF; i++) printf "%-2d | %d\n", i, max[i] }'


0

I don't see your link for the sample file but you can do this by using awk command. if can specify what ever delimiter you may have and exactly what field you need to count. awk '{ FS = "," } ; { if(NR!=1) gsub(/"/, "", $2) ; print NR "|" length($2) } ' test.csv You can redirect this output to any file you want.


3

Similar to archemars but reduced awk -F, ' { for (i=1;i<=NF;i++)l[i]=((x=length($i))>l[i]?x:l[i])} END {for (i in l) print "Column"i":",l[i]}' file Column4: 4 Column5: 3 Column1: 6 Column2: 7 Column3: 4 Also to maintain the order awk -F, ' { for (i=1;i<=NF;i++)l[i]=((x=length($i))>l[i]?x:l[i])} END ...


1

A perl solution: $ perl -F, -anle 'map {$h{$_} = length($F[$_]) if length($F[$_]) > $h{$_}} 0..$#F; END { print "Column @{[$_+1]}: $h{$_}" for sort {$a <=> $b} keys %h }' file Column 1: 6 Column 2: 7 Column 3: 4 Column 4: 4 Column 5: 3


6

why not use awk ? I don't have a mac to test, but length() is a pretty standard function in awk, so this should work. awk file: { for (i=1;i<=NF;i++) { l=length($i) ; if ( l > linesize[i] ) linesize[i]=l ; } } END { for (l in linesize) printf "Columen%d: %d\n",l,linesize[l] ; } then run mybox$ awk -F, -f test.awk a.txt Columen4: 4 ...


0

sed 's/||/| |/g;s/||/| |/g' filename-here The above command is for pipe so replace it with tabspace. You just need to replace empty columns with a blank space and pipe the output to the command you are already using.


1

Using awk: awk -F, '$9!~/Type 0/{print $0}' file AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG Explanation: This causes awk to use , as delimiter (-F,). If the 9th field doesn't ...


1

With awk, you can do: $ awk '$(NF-1)!=0' file AM_AUTO_1,1cx0,A166,B,C118,B,G129,B,A-minor Type I ACG AM_AUTO_2,1cx0,A165,B,C119,B,G128,B,A-minor Type II ACG AM_AUTO_3,1cx0,A166,B,C119,B,G128,B,A-minor Type II ACG AM_AUTO_4,1ddy,A25,A,C21,A,G8,A,A-minor Type I ACG or using grep: grep -v 'Type 0' file



Top 50 recent answers are included