I have two csv files:success.csvID,Legacy ID,Field1, Field21,1111,google,news2,2222,yahoo,newserror.csvLegacy ID,Field1,Field2,Message3333,aol,news,Failed to upload data    4444,cbs,news,Alredy existsHow can I merge these two files and create a new file as shown below? I cannot use indexes as the size and order of fields will keep changing.results.csvID,Legacy ID,Message1,1111,2,2222,,3333,Failed to upload data,4444,Alredy existsThe requirement is to create the results.csv file with only three columns from both success.csv and error.csv.If the row is successfully loaded then we get ID in the success file as the first column with no Message ColumnIf it's failed we get an error in the Message field which is always the last field in the file. In this case the ID will be empty.Read the values from success.csv as follows:awk '{print $1, $2;}' success.csvRead the values from error.csv as follows:awk '{print $1, NF;}' error.csvI am not able to figure out a way to combine both the statements and write the result to a file.
Merge two csvfiles by column header
command line;text processing;scripting;awk;csv