This is appending a column.
My question is fairly simple. I have a program generating data in a form like so:
1 20
2 22
3 23
4 12
5 43
For ever iteration I'm generating this data. I have the basic idea with
cut -f 2 fileA.txt | paste -d >> FileB.txt ????
I want FileB.txt to grow, and my program automatically generates a new filea.txt after every iteration. Thanks for your help guys!
birei
October 15, 2011, 4:15pm
2
Hi theawknewbie,
I don't understand what you try to achieve. What content will be in fileB?
Regards,
Birei
I want FileB to be growing after each iteration.
After 1 iteration, here is FileB:
1 20
2 22
3 23
4 12
5 43
Second iteration, i cut column 2 from the newly made fileA into FileB:
1 20 21
2 22 23
3 23 24
4 12 25
5 43 21
And after the third iteration, fileA is again regenerated, i cut column two from it, append to FileB:
1 20 21 14
2 22 23 15
3 23 24 12
4 12 25 23
5 43 21 38
etc. etc. My problem is that If i paste the columns, i have to give the file a new name. But I want FileB to maintain the same name, essentially to keep appending and appending to FileB.
birei
October 15, 2011, 5:54pm
4
There will be better ways. With this method, create first fileB. And 'awk' command uses an auxiliar file (fileC in my example). Test it:
$ ls -1
fileA
$ cat fileA
1 25
2 27
3 28
4 17
5 48
$ touch fileB
$ ls -1
fileA
fileB
$ awk 'NR == FNR { $1 = ""; sub( /[[:space:]]+/, "", $0 ); fileA[FNR] = $0; next } { print $0 " " fileA[FNR]; fileB_exists = 1 } END { if ( ! fileB_exists ) { for ( i = 1; i <= length(fileA); i++ ) { print fileA } } } ' fileA fileB >fileC; mv fileC fileB
$ cat fileB
25
27
28
17
48
$ awk 'NR == FNR { $1 = ""; sub( /[[:space:]]+/, "", $0 ); fileA[FNR] = $0; next } { print $0 " " fileA[FNR]; fileB_exists = 1 } END { if ( ! fileB_exists ) { for ( i = 1; i <= length(fileA); i++ ) { print fileA } } } ' fileA fileB >fileC; mv fileC fileB
$ cat fileB
25 25
27 27
28 28
17 17
48 48
Regards,
Birei
Birei,
that is sort of the way I was doing it. But the files I'm dealing with become huge, and it's becoming very slow.
I wonder if there is a way to do it in sed?