Tag Info

New answers tagged

2

The following python program should do what you want, or something very close to it. In the desired_output.txt the 3rd line seems to be erroneous: Mem_id#-aa3 : time- file1.txt value = ccx3 / file2.txt value= dd3 the dd3 should probably becc3` Apart from that the output from the program matches except for whitespace, which seems a bit irregular in ...


1

Here's a gawk solution that uses coprocesses to feed each column to a separate instance of sha256sum and reports the total number of unique hashes (the number of unique hashes should coincide with the number of unique columns given that hash collision likelihood with sha256sum is statistically insignificant). While some may consider this an egregious hack, ...


1

Here's a little sed script that I actually wrote for myself not too long ago. I have just had a little fun updating it, though. It does the whole job by itself: cdup() { _u= _d= case "${1#-}" in (U) _u='\)\(';; (D) _d='\ '; _d="$_d\\2$_d";; (*) ! :;;esac && shift sed 's/ */ /g;H;1h;1d;x;:t s/ *\(.*\(\n\)\)\([^ ]\{1,\}\) ...


2

While the canonical way to solve this problem involves paste, here I offer an awk alternative wherein the output record separator is set to a space on odd and newline on even lines awk '{ORS=NR%2?" ":"\n";print}' file


4

The command paste combines lines from multiple input files into one file with multiple columns, one from each file. It can be used to combine lines of the same file into a file with multiple columns, such that consecutive lines end up in consecutive columns in the output. The idea is to use one input multiple times for each row, instead of multiple inputs. ...


2

Feel free to try: paste -d " " - - < filename


2

This question got me interesting and I wanted to follow an approach which I couldn't figure out exactly and got some wonderful help after I posted as a different question . You could understand the approach that am trying to follow from the question I have posted. Although you have specified awk, I hope this could still be helpful for someone having a ...


1

This is a (far from elegant) partial solution to your problem. It uses the first column as id column (it does not have to be the first one but you must definitely have one) and introduces a third dimension suffix to store multiple occurences of the same key. In the end it tries to find those keys of file 2 which have not been found in file 1. BEGIN { ...


3

(((...))), but how to find identical columns? $ printf '%s\n' '1 0 0 0 0 0' '0 1 1 1 0 0' | awk -vSUBSEP='=' ' { for (i=1; i<NF; i++) for (j=i+1; j<=NF; j++) if ($i==$j) M[i,j]++ } END{ for (m in M) if (M[m]==NR) print m }' 5=6 2=3 2=4 3=4 For all columns i<j of each row, increment M[i,j] whenever the ...


8

You can count the unique columns with following pipe: $ awk '{for (i=1; i<=NF; ++i) a[i]=a[i]$i; } END { for (i in a) print a[i] }' foo \ | sort -u | wc -l The awk command transposes your input, the resulting lines are sorted, only unique lines are kept (-u) and at the end all (unique) lines (i.e. the transposed columns) are counted (wc -l). Note ...


2

with paste under bash you can do: paste <(cut -f 4 1.txt) <(cut -f 4 2.txt) .... <(cut -f 4 20.txt) With a python script and any number of files (python scriptname.py column_nr file1 file2 ... filen): #! /usr/bin/env python # invoke with column nr to extract as first parameter followed by # filenames. The files should all have the same number ...


1

The following script does this using awk. I have added for convenience a rownumber, which indicates the number of rows in your files (r). The number of columns you'd like to paste is indicated by c. directory=/your-directory/ r=4 c=20 for n in $(seq 1 $r); do echo "$n" >> rownumber.txt done for n in $(seq 1 $c); do awk '{ print $4}' ...



Top 50 recent answers are included