简体   繁体   中英

How to append list of 2 files in 2 directories

I have 2 directories dir1 and dir2 which has same set of file names like

dir1 
    file1(1 2 3)
    file2
    file3 ....
dir2
    file1(4 5 6)
    file3
    file5 ....

Now I want to append dir1/file1 to dir2/file1 , dir1/file3 to dir2/file3

I need to append only if both files are present in 2 different directories. here dir1/file2 is not in dir2 , so we need to ignore those cases.

The final output should be file1(1 2 3 4 5 6) like this.

I want to append dir1/file1 to dir2/file1 , dir1/file3 to dir2/file3

files=`ls dir1`
cd dir2
files=`ls $files 2>/dev/null`
for file in $files
do  cat ../dir1/$file >>$file
done

Note that since you append dir1/file1 to dir2/file1 , dir2/file1 has 4 5 6 1 2 3 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM