I have a txt file of single column that I will like to divide into multiple columns and label them.
I've tried what I know, but the division is not what I want.
I have a ivmeasurementff.txt which contains:
24.000000
0.003207
0.000002
25.000000
0.003435
0.000002
26.000000
0.003991
0.000002
27.000000
0.003207
0.000002
28.000000
0.003232
0.000002
29.000000
0.003283
pr -ts" " --columns 2 ivmeasurementff.txt
This code just split the column into two
Expected output:
Actual Vol T Vol Current
24.000000 0.003207 0.000002
25.000000 0.003435 0.000002
26.000000 0.003991 0.000002
Actual output:
24.000000 0.003435
0.003207 0.000002
0.000002 26.000000
25.000000 0.003991
You may use paste to format it into 3 columns:
paste - - - < ivmeasurementff.txt
Since there's no header, you have to manually add it:
echo "Actual Vol\tT Vol\tCurrent"; paste - - - < ivmeasurementff.txt
Simple solution with xargs:
xargs -n 3 < Input-file
Or if you are ok with awk.
awk 'FNR%3==0 && FNR!=1{print val,$0;val="";next} {val=(val?val OFS:"")$0} END{if(val){print val}}' Input_file
perl solution:
perl -pe 's{\n$}{ } if $. % 3' Input_file
Take a look at https://docstore.mik.ua/orelly/unix3/upt/ch21_15.htm
Under 21.15.3 it suggests using the -l option
pr -ts" " -l1 -3 ivmeasurementff.txt
24.000000 0.003207 0.000002
25.000000 0.003435 0.000002
26.000000 0.003991 0.000002
27.000000 0.003207 0.000002
28.000000 0.003232 0.000002
29.000000 0.003283
Quoting:
21.15.3. Order Lines Across Columns: -l
Do you want to arrange your data across the columns, so that the first three lines print across the top of each column, the next three lines are the second in each column, and so on, like this?
% pr -l1 -t -3 file1
Line 1 here Line 2 here Line 3 here
Line 4 here Line 5 here Line 6 here
Line 7 here Line 8 here Line 9 here
... ... ...
Use the -l1 (page length 1 line) and -t (no title) options. Each "page" will be filled by three lines (or however many columns you set). You have to use -t; otherwise, pr will silently ignore any page lengths that don't leave room for the header and footer. That's just what you want if you want data in columns with no headings.
Simply add option -a and specify three columns.
$ pr -ats" " --columns 3 ivmeasurementff.txt
24.000000 0.003207 0.000002
25.000000 0.003435 0.000002
26.000000 0.003991 0.000002
27.000000 0.003207 0.000002
28.000000 0.003232 0.000002
29.000000 0.003283
I'm not sure why this works. Seems like pr treats columns as rows in some cases?
Related
This is odd . . .
I have a Chart with ten sets of "x-y" data.
But now I have tried to put in two more - and Excel ignores the first column which it regards as sequential, i.e.
Instead of
4.41 1103
6.91 1262
7.06 1275
7.89 1329
it treats it as
1 1103
2 1262
3 1275
4 1329
How do I prevent this ?
I have tab delimited files as shown below:
CNV_chr1_12623251_12632176 8925 3 RR123 XX
CNV_chr1_13398757_13402091 3334 4 RR123 YY
CNV_chr1_13398757_13402091 3334 4 RR224 YY
CNV_chr1_14001365_14004064 2699 1 RR123 YX
CNV_chr1_14001365_14004064 2699 1 RR224 YX
Columns $1 and $2 stay identical. In this case, i would need to remove the duplicate row by indexing with the value in 4th column. and add an additional $5 with number of strings separated by comma in $4. Sample output shown below:
CNV_chr1_12623251_12632176 8925 3 RR123 1 XX
CNV_chr1_13398757_13402091 3334 4 RR123,RR124 2 YY
CNV_chr1_14001365_14004064 2699 1 RR123,RR224 2 YX
Any working soultion would be helpful.
Try this:
awk '($1 in ar){ar[$1]=ar[$1]; br[$1]=br[$1]","$4; next;}
{br[$1]=$4; $4="REPLACE_ME"; ar[$1]=$0}
END{for(key in ar){c=split(br[key],s,",")
gsub("REPLACE_ME", br[key] FS c, ar[key])
print ar[key]}}' test.txt
The output:
CNV_chr1_14001365_14004064 2699 1 RR123,RR224 2 YX
CNV_chr1_13398757_13402091 3334 4 RR123,RR224 2 YY
CNV_chr1_12623251_12632176 8925 3 RR123 1 XX
For tab-delimited input just add -F"\t" to awk:
awk -F"\t" '($1 in ar){ar[$1]=ar[$1]; br[$1]=br[$1]","$4; next;}
{br[$1]=$4; $4="REPLACE_ME"; ar[$1]=$0}
END{for(key in ar){c=split(br[key],s,",")
gsub("REPLACE_ME", br[key] FS c, ar[key])
print ar[key]}}' test.txt
and get:
CNV_chr1_14001365_14004064 2699 1 RR123,RR224 2 YX
CNV_chr1_13398757_13402091 3334 4 RR123,RR224 2 YY
CNV_chr1_12623251_12632176 8925 3 RR123 1 XX
Can any one help to merge defferent files by common data (columns)? please =(
file1.txt
ID Kg Year
3454 1000 2010
3454 1200 2011
3323 1150 2009
2332 1000 2011
3454 1156 201
file2.txt
ID Place
3454 A1
3323 A2
2332 A6
5555 A9
file 1+2
ID Kg Year Place
3454 1000 2010 A1
3454 1200 2011 A1
3323 1150 2009 A2
2332 1000 2011 A6
3454 1156 2013 A1
So second file should be connected to first. As you can see ID 5555 from file 2 just not using.
How to do it in linux or....
If you start with sorted files, the tool is join. In your case, you can sort on the fly.
join <(sort file1.txt) <(sort file2.txt)
The headers will be joined as well but won't appear on top. Pipe to sort -r
If you don't care about maintaining the order of lines, use karakfa's join command.
To keep the original order of lines, use awk
awk '
NR==FNR {place[$1]=$2; next}
$1 in place {print $0, place[$1]}
' file2.txt file1.txt | column -t
ID Kg Year Place
3454 1000 2010 A1
3454 1200 2011 A1
3323 1150 2009 A2
2332 1000 2011 A6
3454 1156 201 A1
I have a text file that needs to be sorted, my goal is to only keep the longest sequences in each of my modules. My text file looks like this:
1 abc 35
1 def 90
1 ghi 100
2 jui 500
3 yui 500
3 iop 300
My goal is to sort unique modules (first column) by keeping highest number from column 3, just like this:
1 ghi 100
2 jui 500
3 yui 500
So far I checked the sort options but without success, I guess awk could also do it!
I tried:
sort -u -k1,1 Black.txt | sort -k3n,3
Any help would be much appreciated!
You sort them based on the third column first and later unique them by first column.
sort -r -k 1 -k3n,3 Black.txt|sort -u -k1,1
output
1 ghi 100
2 jui 500
3 yui 500
I have a bunch of data, ordered below one another in excel (actually openoffice). I need them to be consolidated by the first column, but so that all data are still shown:
From (actually goes until 100):
1 283.038 244
1 279.899 494
1 255.139 992
1 254.606 7329
1 254.5 17145
1 251.008 23278
1 250.723 28758
1 247.753 92703
1 243.43 315278
1 242.928 485029
1 237.475 1226549
1 233.851 2076295
1 232.833 9826327
1 229.656 15965410
1 229.656 30000235
2 286.535 231
2 275.968 496
2 267.927 741
2 262.647 2153
2 258.925 3130
2 253.954 4857
2 249.551 9764
2 244.725 36878
2 243.825 318455
2 242.86 921618
2 238.401 1405028
2 234.984 3170031
2 233.168 4403799
2 229.317 8719139
2 224.395 26986035
2 224.395 30000056
3 269.715 247
3 268.652 469
3 251.214 957
3 249.04 30344
3 245.883 56115
3 241.753 289668
3 241.707 954750
3 240.684 1421766
3 240.178 1865750
3 235.09 2626524
3 233.579 5129755
3 232.517 7018880
3 232.256 18518741
3 228.75 19117443
3 228.75 30000051
to:
1 2 3
283.038 244 286.535 231 269.715 247
279.899 494 275.968 496 268.652 469
255.139 992 267.927 741 251.214 957
254.606 7329 262.647 2153 249.04 30344
254.5 17145 258.925 3130 245.883 56115
251.008 23278 253.954 4857 241.753 289668
250.723 28758 249.551 9764 241.707 954750
247.753 92703 244.725 36878 240.684 1421766
243.43 315278 243.825 318455 240.178 1865750
242.928 485029 242.86 921618 235.09 2626524
237.475 1226549 238.401 1405028 233.579 5129755
233.851 2076295 234.984 3170031 232.517 7018880
232.833 9826327 233.168 4403799 232.256 18518741
229.656 15965410 229.317 8719139 228.75 19117443
229.656 30000235 224.395 26986035 228.75 30000051
224.395 30000056
This must be really simple. But I couldn't find it. I tried a pivot table, but that only allows me to summarise or count etc the fields, while I want them all to be displayed. Any ideas?
To elaborate on the pivot table. I put column 1 as row, column 2 as colum and column 3 in the middle, but that comes out with a lot of empty cells and summarised.
I am not sure on which search terms to look, unconsolidised pivot tables haven't provided an answer.
After some discussions with my collegues, this seemed undoable in excel. So I just created a short script to save each "run" (which is the first column) in a seperate file, from csv:
awk -F, '{print > $1}' rw.txt