conditionally combine text from two files into one

Hi! I'm trying to take multiple text files (6), which have text on some lines but not others, and combine them. I'd also like to make the values in one column of some of the files (files 4-6) negative. I'm trying to write a short script (see below) as I have to do this with a large number of files. Any advice much appreciated! Example:

Input text file 1:

0          1.3           1


34         4             1

.....

Input text file 2:

10          0.3           1


24         3             1

.....

Output text file:

0          1.3           1
34         4             1
.....
10         0.3          -1
24         3             -1
.....

What I have so far follows. problems: it does not get rid of the rows of empty text (it puts 0.000 in them), and it doesn't work consistently (sometimes it only takes the first line of an input file and ignores the others).

#!/bin/bash
awk  '{printf("%f %f %f\n", $1, $2, $3)}' *positive_files*.txt > file_1.txt
awk  '{printf("%f %f -%f\n", $1, $2, $3)}' *negative_files*txt >> file_1.txt
awk  'NF{printf("%f %f %f\n", $1, $2, $3)}' *positive_files*.txt > file_1.txt
awk  'NF{printf("%f %f -%f\n", $1, $2, $3)}' *negative_files*txt >> file_1.txt

Thank you very much! Thanks also for fixing the formatting of my posted code. f :slight_smile:

Unfortunately this doesn't work though, it still spits out 0s for all the rows that I'm not interested in. I just added a sed command to replace the 0s with spaces to fix this up.

One other thing � it's still doing this weird thing where sometimes it only takes the first line of a text file, any advice? e.g., output might be:

0          1.3           1
10         0.3          -1
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
24         3             -1
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
.....