I have a strange situation of sorting and merging two files based on similar columns
previusly both files has same count of records so, I made below way which is working fine until they reduced the count of one files .
I.e. some times the count of records of both will same and some times it won't but only the columns will remain unchanged .
cat /var/tmp/today.csv > /var/tmp/outputfile
for file in `ls /var/tmp/yday.csv | xargs `
do
cut -d"," -f7,8,9 $file > /var/tmp/tmp
paste -d"," /var/tmp/outputfile /var/tmp/tmp >> /var/tmp/final_outputfile
done
working well for same row count files
and columns we are talking about are 1,2,3,5,6 which are common in both files.
now files has changed
for today
36000807 A 123 78 0 1 0.1 0.2 0.3
36000807 A 123 79 0 1 -0.1 0.2 -0.3
36000807 A 123 78 0 5 0.1 0.2 0.3
36000807 A 123 79 0 5 -0.1 0.2 -0.3
36000807 A 123 78 0 10 0.1 0.2 0.3
36000807 A 123 79 0 10 -0.1 0.2 -0.3
for yday.csv
36000807 A 123 76 0 1 0.1 0.2 0.3
36000807 A 123 76 0 5 -0.1 0.2 -0.3
36000807 A 123 76 0 10 -0.1 0.2 -0.3
now final_outputfile
should looklike
36000807 A 123 78 0 1 0.1 0.2 0.3 0.1 0.2 0.3
36000807 A 123 79 0 1 -0.1 0.2 -0.3 NA NA NA
36000807 A 123 78 0 5 0.1 0.2 0.3 -0.1 0.2 -0.3
36000807 A 123 79 0 5 -0.1 0.2 -0.3 NA NA NA
36000807 A 123 78 0 10 0.1 0.2 0.3 -0.1 0.2 -0.3
36000807 A 123 79 0 10 -0.1 0.2 -0.3 NA NA NA
it's possible for yday.csv first row could be missing totally or any other rows
then
final_output should be looklike
36000807 A 123 78 0 1 0.1 0.2 0.3 NA NA NA
36000807 A 123 79 0 1 -0.1 0.2 -0.3 NA NA NA
36000807 A 123 78 0 5 0.1 0.2 0.3 -0.1 0.2 -0.3
36000807 A 123 79 0 5 -0.1 0.2 -0.3 NA NA NA
36000807 A 123 78 0 10 0.1 0.2 0.3 -0.1 0.2 -0.3
36000807 A 123 79 0 10 -0.1 0.2 -0.3 NA NA NA
anyone have any idea to work this out?