Skip to main content
added 448 characters in body
Source Link
Tommaso
  • 167
  • 1
  • 10

Moreover, if in input2.txt I would like to replace the element of the last column only with the string "P" for rows that have an ID equal or grated than 4000, how can I do?

i.e I would like to replace for only the first row (ID = 4304) the last "C" with "P"

output.txt

4304,N,-9.700,-7.680,58.330,-2.3,P 2940,S,-10.440,-3.450,54.270,2.2,S 2900,C,-13.655,-13.730,59.405,-1.5,C 2931,C,-9.910,-2.420,57.610,0.2,C 

Moreover, if in input2.txt I would like to replace the element of the last column only with the string "P" for rows that have an ID equal or grated than 4000, how can I do?

i.e I would like to replace for only the first row (ID = 4304) the last "C" with "P"

output.txt

4304,N,-9.700,-7.680,58.330,-2.3,P 2940,S,-10.440,-3.450,54.270,2.2,S 2900,C,-13.655,-13.730,59.405,-1.5,C 2931,C,-9.910,-2.420,57.610,0.2,C 
Became Hot Network Question
Copy edited
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

matched and not matched ID firtsfirst column

I have two input.txtinput.txt files on a Linux machine containing different columns (",", as separator). I have a script to join thisthese files using the ID reported in eacheach's first column. This script preserved in the outputpreserves files all IDIDs of the first filesfile in the output and only the matched ID of the second one. I need to implement this script adding an option to preserved also preserve the ID of the second files not matched with the ID of the firsfirst one.

I'd like to modify the cmd linecommand to obtainedobtain two output, the files. The first should be similar to the previously outputwhat I get now, but addingit should also have the IDs that were not matched ID of the second input:

The other output file should containscontain only the not matchingnon-matching rows of input2.txtinput2.txt:

matched and not matched ID firts column

I have two input.txt files containing different columns ("," as separator). I have a script to join this files using the ID reported in each first column. This script preserved in the output files all ID of the first files and only the matched ID of the second one. I need to implement this script adding an option to preserved also ID of the second files not matched with the ID of the firs one.

I'd like to modify the cmd line to obtained two output, the first should be similar to the previously output but adding also the not matched ID of the second input

The other output should contains only the not matching rows of input2.txt

matched and not matched ID first column

I have two input.txt files on a Linux machine containing different columns (, as separator). I have a script to join these files using the ID reported in each's first column. This script preserves files all IDs of the first file in the output and only the matched ID of the second one. I need to implement this script adding an option to also preserve the ID of the second files not matched with the ID of the first one.

I'd like to modify the command to obtain two output files. The first should be similar to what I get now, but it should also have the IDs that were not matched:

The other output file should contain only the non-matching rows of input2.txt:

Source Link
Tommaso
  • 167
  • 1
  • 10

matched and not matched ID firts column

I have two input.txt files containing different columns ("," as separator). I have a script to join this files using the ID reported in each first column. This script preserved in the output files all ID of the first files and only the matched ID of the second one. I need to implement this script adding an option to preserved also ID of the second files not matched with the ID of the firs one.

Example:

2931,C,-9.750,-2.550,57.910,-0.3,C 2932,C,-5.470,-0.200,51.550,0.9,C 2940,C,-10.860,-3.400,54.000,0.7,C 2941,S,-11.820,-13.550,55.070,2.1,S 2944,H,-3.770,-4.180,60.300,0.7,H 

input2.txt

4304,N,-9.700,-7.680,58.330,-2.3,N 2940,S,-10.440,-3.450,54.270,2.2,S 2900,C,-13.655,-13.730,59.405,-1.5,C 2931,C,-9.910,-2.420,57.610,0.2,C 

cmd:

join -t, -a1 -o auto <(sort input1.txt) <(sort input2.txt) > output.txt.txt 

output.txt

2931,C,-9.750,-2.550,57.910,-0.3,C,2931,C,-9.910,-2.420,57.610,0.2,C 2932,C,-5.470,-0.200,51.550,0.9,C,,,,,,, 2940,C,-10.860,-3.400,54.000,0.7,C,2940,S,-10.440,-3.450,54.270,2.2,S 2941,S,-11.820,-13.550,55.070,2.1,S,,,,,,, 2944,H,-3.770,-4.180,60.300,0.7,H,,,,,,, 

I'd like to modify the cmd line to obtained two output, the first should be similar to the previously output but adding also the not matched ID of the second input

output_final.txt

2931,C,-9.750,-2.550,57.910,-0.3,C,2931,C,-9.910,-2.420,57.610,0.2,C 2932,C,-5.470,-0.200,51.550,0.9,C,,,,,,, 2940,C,-10.860,-3.400,54.000,0.7,C,2940,S,-10.440,-3.450,54.270,2.2,S 2941,S,-11.820,-13.550,55.070,2.1,S,,,,,,, 2944,H,-3.770,-4.180,60.300,0.7,H,,,,,,, ,,,,,,,2900,C,-13.655,-13.730,59.405,-1.5,C ,,,,,,,4304,N,-9.700,-7.680,58.330,-2.3,N 

The other output should contains only the not matching rows of input2.txt

output2.txt

2900,C,-13.655,-13.730,59.405,-1.5,C 4304,N,-9.700,-7.680,58.330,-2.3,N