Visit Our UNIX and Linux User Community

Insert file names when concatenate files into a file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert file names when concatenate files into a file
# 1  
Old 06-05-2009
Question Insert file names when concatenate files into a file


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
# 2  
Old 06-05-2009
You can use a loop like this:

for i in test_*; do echo Filename : "$i";echo;cat "$i"; done > bigfile

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 06-05-2009
Originally Posted by Franklin52
You can use a loop like this:

for i in test_*; do echo Filename : "$i";echo;cat "$i"; done > bigfile

Thank you so much!
It worked.Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #957
Difficulty: Medium
Metamorphic code is code that when run outputs a logically equivalent version of its own code under some interpretation.
True or False?

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. Shell Programming and Scripting

Delete files except the file names available in the Except File

Hi, I need some help in the below scenario. I need to delete all the files from the directory except the file name available in the Except file. Like the folder ABC have files like A1.txt,A2.txt......A10.txt and also have a file named Except.txt with the content A3.txt,A4.txt Need a... (6 Replies)
Discussion started by: kban
6 Replies

3. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

4. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

5. Shell Programming and Scripting

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. Testreport_Server1.txt ============ MonitoringReport_Server1.txt============ CentralReport_Server1 Here two files containing server1 should be merged into one file? How can i do... (16 Replies)
Discussion started by: sharsour
16 Replies

6. UNIX for Dummies Questions & Answers

Delete files whose file names are listed in a .txt file

hi, I need a help. I used this command to list all the log files which are for more than 10 days to a text file. find /usr/script_test -type f -mtime +10>>/usr/ftprm.txt I want all these files listed in the ftprm.txt to be ftp in another machine and then rm the files. Anyone can help me... (8 Replies)
Discussion started by: kamaldev
8 Replies

7. 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

8. Shell Programming and Scripting

awk to insert a files names

I have a couple of text files which are named as 1.txt 2.txt 1000.txt 11.txt I want to cat/merge the contents of each text file into one single file like this 1 content of 1.txt 2 content of 2.txt 1000 content of 1000.txt 11 content of 11.txt (2 Replies)
Discussion started by: Lucky Ali
2 Replies

9. Shell Programming and Scripting

How to split a data file into separate files with the file names depending upon a column's value?

Hi, I have a data file xyz.dat similar to the one given below, 2345|98|809||x|969|0 2345|98|809||y|0|537 2345|97|809||x|544|0 2345|97|809||y|0|651 9685|98|809||x|321|0 9685|98|809||y|0|357 9685|98|709||x|687|0 9685|98|709||y|0|234 2315|98|809||x|564|0 2315|98|809||y|0|537... (2 Replies)
Discussion started by: nithins007
2 Replies

10. 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

Featured Tech Videos