Home Merge multiple files in multiple directories - bash
Reply: 0

Merge multiple files in multiple directories - bash

user1310
1#
user1310 Published in May 22, 2018, 12:12 am

We have a requirement to loop multiple directiories and in each directory there will be, multiple text files with Pattern File"n".txt which needs to merged to one, File.txt

We are using Bourne Shell scripting.

Example:

/staging/dusk/inbound/ --> Main Directory

Dir1
File1.txt,File2.txt,..sample1.doc,sample2.pdf,File*.txt  --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

Dir2
File1.txt,File2.txt,..attach1.txt,sample1.doc, File*.txt --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

Dir3
File1.txt,File2.txt,File*.txt,..sample1,sample2*.txt --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

Dir4
File1.txt,File2.txt,File*.txt,..temp.doc,attach.txt --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

Di5
File1.txt,File2.txt,File*.txt,..sample1,sample2*.txt --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

Dir"n"
File1.txt,File2.txt,File3.txt,File*.txt..attach1,attach*.txt --> we have to Merge the File name which starts with Fil*.txt -->Final.txt

The files from each directory can be looped using cat *.txt > all.txt command.

But how we loop the directiories?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315339 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO