Tag Info

New answers tagged

0

if the order doesn't matter, you can simply use this: awk '{for(i=2;i<=NF;i++)print $1,$i}' file


0

Awk this awk script will work on an arbitrary number of columns > 2 and order of appearance will be preserved as across then down with no assumptions made about what the columns are (i.e. doesn't matter if they are numeric or not, sorted or not, etc): { for (i = 2; i <= NF; i++) { a[j + i] = $1 " " $i } j += (i - 1); } END { ...


0

Here is an awk solution: $ awk '{a[i++]=$1" "$3;print $1,$2}END{for(i=0;i<length(a);i++){print a[i]}}' file 0 0 0.05 9.6877884e-06 0.1 4.2838688e-05 0.15 0.00016929444 0.2 0.00036426881 0.25 0.00055234582 0.3 0.00077448576 0.35 0.00082546537 0.4 0.0012371619 0.45 0.0013286382 0 0 0.05 0.0024898597 0.1 0.0049595502 0.15 0.0074092494 0.2 0.009839138 0.25 ...


1

Oh, that's an easy one. Here's a simple version that keeps the order of the keys as they appear in the file: $ awk -F, ' /.+/{ if (!($1 in Val)) { Key[++i] = $1; } Val[$1] = Val[$1] "," $2; } END{ for (j = 1; j <= i; j++) { printf("%s %s\n%s", Key[j], Val[Key[j]], (j == i) ? "" : "\n"); } ...


4

If you don't mind the order of output: $ awk -F',' 'NF>1{a[$1] = a[$1]","$2}END{for(i in a){print i""a[i]}}' file jkl, words and numbers, words and numbers, words and numbers, words and numbers abc, 12345, 56345, 15475, 123345 ghi, something else, something else, something else, something else def, text and nos, text and nos, text and nos, text and nos ...


0

The problem is of course with column not differentiating between printing and non-printing characters, bash gets around this in its prompt (PS1) with its \[ \] escape feature, I don't know of anything else that does exactly that. I tried a quick and nasty hack, given that your problematic field is at the start of the line, move it to the then end, but you ...


1

I don't think there's such a command, you'd have to do by hand. Something like: awk ' { nf[NR]=NF for (i = 1; i <= NF; i++) { f[NR,i] = $i gsub(/\033\[[0-9;]*[mK]/, "", $i) len[NR,i] = l = length($i) if (l > max[i]) max[i] = l } } END { for (n = 1; n <= NR; n++) { for (i = 1; i < nf[n]; i++) ...


0

Some sed work would do the trick: a sed to remove ANSI color codes sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" a sed to replace space(s) with tabs sed -r "s/\s+/\t/g" Finaly: printf "\033[0;32;1mgreen_apple\033[0m 1 100 orange 20 19 pineapple 1000 87 avocado 4 30" \ | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" \ | sed -r ...


1

You will have to printf "%s\n" "$str1" "$str2" | column -t and then inject the headers Generically, I'd write something like this that uses arrays: strings=( "$str1" "$str2" ... ) headers=( "STRING SHORT" "STRING LONG" ... ) exec 3< <( printf "%s\n" "${strings[@]}" | column -t ) for (( i=0; i<${#strings[@]}; i++)); do printf -- ...



Top 50 recent answers are included