Hi, I was wondering if anyone could assist me for (what is probably) a very straightforward answer.
I have input files containing something like
File 1
Apples
Apples
Apples
Apples
File 2
Bananas
Bananas
Bananas
Bananas
etc
I want to add a second column where the same number is equal to each fruit e.g. and these need to be sequential (ie, file 1, column 2 value = 1, file 2, column 2 value = 2) etc. The output files would look like this:
File 1
Apples 1
Apples 1
Apples 1
Apples 1
File 2
Bananas 2
Bananas 2
Bananas 2
Bananas 2
File 3
Pears 3
Pears 3
Pears 3
Pears 3
I can write the loop for the different fruits easily enough, the problem is adding 1 to the column in each subsequent file. I tried using awk to print values into the second column directly:
awk '{(($2=1))}1' apples.txt > apples_with_1_in_second_column.txt
This works fine for running individual fruits. Unfortunately, this is a small example and I have hundreds of different files like this and it would take ages to do each one individually.
I was thinking something like:
fruit=(apples bananas pears)
for i in {0..2}
do
awk '{$2=(Value + 1 for each subsequent file}1' ${fruit[$i]}.txt > ${fruit[$i]}_with_number_in_second_column.txt
done
Can anyone suggest a generic script that would allow me to do this for hundreds of files like the one above? I'm not married to a solution using awk and any assistance would be very much appreciated.