How to concatenate the files based upon the file name?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to concatenate the files based upon the file name?
# 1  
Old 08-01-2013
How to concatenate the files based upon the file name?

Hi Experts,

I am trying to merge multiple files into one file based upon the file name.

Code:
 
Testreport_Server1.txt         ============
MonitoringReport_Server1.txt============  CentralReport_Server1

Here two files containing server1 should be merged into one file?

How can i do this using shell. I was thinking something like below but not working

Code:
 
cat $DR_HOME/OS/Server1*.txt >> Central_Report_Server1

# 2  
Old 08-01-2013
Code:
cat $DR_HOME/OS/*Server1.txt >> Central_Report_Server1

# 3  
Old 08-01-2013
Thanks Krish,

I tried that also but not working.
Giving me error. "No such file or directory"

I am using bash.
# 4  
Old 08-01-2013
Are you able to list the files ending with Server1.txt using below command?

Code:
ls $DR_HOME/OS/*Server1.txt

Is the variable DR_HOME set to correct value?
Is OS a subdirectory?
# 5  
Old 08-01-2013
Hello,

Could you please let us know what is the value of
Code:
$DR_HOME

here ?


Thanks,
R. Singh
# 6  
Old 08-01-2013
Code:
DR_HOME='/home/user/Test/'

Inside this I have OS folder and than files with name containing Server1
# 7  
Old 08-01-2013
Hello,

Could you please use the followinf script to get your desired Output.
Lets say appending_file.ksh is the script name and path where files are present /home/user/bin/singh_testing/awk_programming/testing_appending_file_date.


Our script is in /home/user/bin/singh_testing/awk_programming.

Code:
 
$ cat appending_file.ksh
cd /home/archsupp/bin/singh_testing/awk_programming/testing_appending_file_date

if [[ -e test ]]
then
> test
fi

value=`ls -ltr | awk '{print $9}'| grep -v "test"`
set -A array_value $value

for i in ${array_value[@]}
do
cd /home/archsupp/bin/singh_testing/awk_programming/testing_appending_file_date
cat $i >> test

echo "**************************" >> test

done
echo "Script has been completed now."
$



Output wil be stored at /home/archsupp/bin/singh_testing/awk_programming/testing_appending_file_date in test file.

Code:
$ cat test
this is first test file.
As per requirement.
**************************
This is the second file.
As per the R. Singh
lets see the appending process here.
**************************
$


So you can change the path value in script and try the same it should work properly.


Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate files based on names

Dear all, I have a list of files and I woulk like to concatenate some of them based on their name. Basically my files are names like that: file1_abcd_other_useless_letters_1_C1.txt file1_abcd_other_useless_letters_1_C2.txt file1_xywz_other_useless_letters_1_C1.txt... (4 Replies)
Discussion started by: giuliangiuseppe
4 Replies

2. UNIX for Dummies Questions & Answers

Concatenate files and delete source files. Also have to add a comment.

- Concatenate files and delete source files. Also have to add a comment. - I need to concatenate 3 files which have the same characters in the beginning and have to remove those files and add a comment and the end. Example: cat REJ_FILE_ABC.txt REJ_FILE_XYZ.txt REJ_FILE_PQR.txt >... (0 Replies)
Discussion started by: eskay
0 Replies

3. UNIX for Dummies Questions & Answers

Concatenate Several Files to One

Hi All, Need your help. I will need to concatenate around 100 files but each end of the file I will need to insert my name DIRT1228 on each of the file and before the next file is added and arrived with just one file for all the 100files. Appreciate your time. Dirt (6 Replies)
Discussion started by: dirt1228
6 Replies

4. Shell Programming and Scripting

Concatenate many files which contents the same date as part of name file

Gents, I have lot of files in a folder where each file name includes the date of generation, then I would like to merge all the files for each date in a complete file. list of files in forder. dsd01_121104.txt dsd01_121105.txt dsd01_121106.txt dsd03_121104.txt dsd03_121105.txt... (7 Replies)
Discussion started by: jiam912
7 Replies

5. Shell Programming and Scripting

Concatenate files

Hi, I want to create a batch(bash) file to combine 23 files together. These files have the same extension. I want the final file is save to a given folder. Once it is done it will delete the 23 files. Thanks for help. Need script. (6 Replies)
Discussion started by: zhshqzyc
6 Replies

6. Shell Programming and Scripting

Concatenate files to one file with naming convention

Hi , i have below files in wrk folder. file names are 1102090001.CLT 1102090003.CLT 1102100019.CLT 1102100020.CLT the above files are concatenate to one file but that concatenate file name must be same naming convention. (date +%y%m%d)and 0001 count. example : concatenate file... (9 Replies)
Discussion started by: krbala1985
9 Replies

7. Shell Programming and Scripting

Concatenate files

I have directory structure sales_only under which i have multiple directories for each dealer example: ../../../Sales_Only/xxx_Dealer ../../../Sales_Only/yyy_Dealer ../../../Sales_Only/zzz_Dealer Every day i have one file produce under each directory when the process runs. The requirement... (3 Replies)
Discussion started by: mohanmuthu
3 Replies

8. Shell Programming and Scripting

want to concatenate multiple files based on the rest of ls -lrt

uadm@4132> ls -lrt -rw------- 1 uadm uadm 3811819 Jun 6 04:08 data_log-2010.05.30-10:04:08.txt -rw------- 1 uadm uadm 716246 Jun 13 01:38 data_log-2010.06.06-10:04:08.txt -rw------- 1 uadm uadm 996 Jun 13 04:00 data_log-2010.06.06-10:04:22.txt -rw------- 1 uadm uadm 7471 Jun 20 02:03... (5 Replies)
Discussion started by: mail2sant
5 Replies

9. Shell Programming and Scripting

Concatenate multiple lines based.

Hello, I have been searching the forum for concatenation based on condition. I have been close enough but not got th exact one. infile: -----DB_Name ABC (X, Y,Z). DB_Name DEF (T). DB_Name GHI (U ,V,W). Desired Output file should be: ---------------------------DB_Name ABC... (8 Replies)
Discussion started by: indrajit_u
8 Replies

10. Shell Programming and Scripting

Insert file names when concatenate files into a file

Hi I found the following line would concatenate all test_01 test_02 test_03 files into "bigfile". cat test_* >> bigfile But, what I'm looking for a way to insert each file names in order when concatenated in "bigfile". Thank you samky2005 (2 Replies)
Discussion started by: samky2005
2 Replies
Login or Register to Ask a Question