Concatenation of files with same naming patterns dynamically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenation of files with same naming patterns dynamically
# 1  
Old 08-22-2016
Concatenation of files with same naming patterns dynamically

Since my last threads were closed on account of spamming, keeping just this one opened!

Hi,

I have the following reports that get generated every 1 hour and this is my requirement:

1. 5 reports get generated every hour with the names
Code:
"Report.Dddmmyy.Thhmiss.CTLR"
"Report.Dddmmyy.Thhmiss.ACCD"
"Report.Dddmmyy.Thhmiss.BCCD"
"Report.Dddmmyy.Thhmiss.CCCD"
"Report.Dddmmyy.Thhmiss.DDDD"

2. At the end of the day I need to concatenate all reports with similar names into a single file.
For example: 24 files for pattern "Report.Dddmmyy.Thhmiss.CTLR" into a single file called "Test.dat" and so on.

3.Please note that the last four letters of the file name will be a constant and the reports have to be concatenated using this.

4. I do not want to parameterize just these last four letters or list the last four letter as ls -l *CTLR* as this will be hard coding so could there be a better way of handling this!?

Kindly advise.

Thanks,
Jess

Last edited by Don Cragun; 08-23-2016 at 04:14 AM.. Reason: code tags, please!
# 2  
Old 08-22-2016
something along these lines assuming you're in the directory where the files are located - not tested...
Code:
#!/bin/ksh

today=$(date +%d%m%y)

ls -1 Report.D${today}* | awk -F. '
{ a[$NF]}
END {for (i in a) print i}
' | while read ext junk
do
   cat Report.D${today}*.${ext} > DailyReport.D${today}.${ext}
done


Last edited by vgersh99; 08-22-2016 at 07:53 PM..
# 3  
Old 08-23-2016
Here a simple solution for the Z-Shell (since you didn't indicate any preference to a shell, I assume that you are open, which one to use):

Assume that you have parameterized the file extension using an array, for instance

Code:
extensions=(ACCD BCCD CCCD DCCD)

You can now produce a file consisting of the catenation of the individual files by

Code:
cat Report.Dddmmyy.Thhmiss.${^extensions}

This assumes that these files all exist, i.e. if one of the files doesn't exist, you get an error message. It is also possible to provide a solution, where non-existing files are siltently skipped, but this is not in the scope of your question.
# 4  
Old 08-23-2016
Quote:
Originally Posted by Jesshelle David
Since my last threads were closed on account of spamming, keeping just this one opened!

Hi,

I have the following reports that get generated every 1 hour and this is my requirement:

1. 5 reports get generated every hour with the names
Code:
"Report.Dddmmyy.Thhmiss.CTLR"
"Report.Dddmmyy.Thhmiss.ACCD"
"Report.Dddmmyy.Thhmiss.BCCD"
"Report.Dddmmyy.Thhmiss.CCCD"
"Report.Dddmmyy.Thhmiss.DDDD"

2. At the end of the day I need to concatenate all reports with similar names into a single file.
For example: 24 files for pattern "Report.Dddmmyy.Thhmiss.CTLR" into a single file called "Test.dat" and so on.

3.Please note that the last four letters of the file name will be a constant and the reports have to be concatenated using this.

4. I do not want to parameterize just these last four letters or list the last four letter as ls -l *CTLR* as this will be hard coding so could there be a better way of handling this!?

Kindly advise.

Thanks,
Jess
I don't understand what you're trying to do. I get that at sometime shortly before midnight on August 23, 2016 you will have 24 files matching the pattern Report.D230816.T??????.CTLR, 24 files matching the pattern Report.D230816.T??????.ACCD, 24 files matching the pattern Report.D230816.T??????.BCCD, 24 files matching the pattern Report.D230816.T??????.CCCD, and 24 files matching the pattern Report.D230816.T??????.DDDD.

And I get that you want to copy the contents of the 24 files matching the pattern Report.D230816.T??????.CTLR into a file named Test.dat. I don't know what "and so on" means? Are you saying that you want to overwrite that file four times so at that at midnight on the morning of August 24, 2016, the file Test.dat will contain the contents of the 24 files matching the pattern Report.D230816.T??????.DDDD? This doesn't make any sense to me, but that seems to be what you are requesting.

And, you say that the script you are writing can't have the strings CTLR, ACCD, BCCD, CCCD, and DDDD built in. Is this because some days may have additional filename extensions? Is it because the set of filename extensions changes from day to day? Are all of the extensions you want to process four characters long? If not, how do we determine which files are supposed to be processed? (And, if the *.CTLR files are supposed to be processed before the *.ACCD files (i.e., not in alphabetic order), if the extensions aren't built into the script, how is the script supposed to know which extension should be processed first?
# 5  
Old 08-24-2016
Quote:
Originally Posted by Don Cragun
I don't understand what you're trying to do. I get that at sometime shortly before midnight on August 23, 2016 you will have 24 files matching the pattern Report.D230816.T??????.CTLR, 24 files matching the pattern Report.D230816.T??????.ACCD, 24 files matching the pattern Report.D230816.T??????.BCCD, 24 files matching the pattern Report.D230816.T??????.CCCD, and 24 files matching the pattern Report.D230816.T??????.DDDD.

And I get that you want to copy the contents of the 24 files matching the pattern Report.D230816.T??????.CTLR into a file named Test.dat. I don't know what "and so on" means? Are you saying that you want to overwrite that file four times so at that at midnight on the morning of August 24, 2016, the file Test.dat will contain the contents of the 24 files matching the pattern Report.D230816.T??????.DDDD? This doesn't make any sense to me, but that seems to be what you are requesting.

And, you say that the script you are writing can't have the strings CTLR, ACCD, BCCD, CCCD, and DDDD built in. Is this because some days may have additional filename extensions? Is it because the set of filename extensions changes from day to day? Are all of the extensions you want to process four characters long? If not, how do we determine which files are supposed to be processed? (And, if the *.CTLR files are supposed to be processed before the *.ACCD files (i.e., not in alphabetic order), if the extensions aren't built into the script, how is the script supposed to know which extension should be processed first?
Hi Don,

Let me elaborate! These reports are generated from a mainframe and sent to a UNIX box every hour! There are 5 reports as I mentioned earlier!

What I need to do is to concatenated me the same type of reports into one and then give it an extension so it is readable and I can split the reports as and when I want to!

---------- Post updated at 02:03 AM ---------- Previous update was at 02:02 AM ----------

Quote:
Originally Posted by vgersh99
something along these lines assuming you're in the directory where the files are located - not tested...
Code:
#!/bin/ksh

today=$(date +%d%m%y)

ls -1 Report.D${today}* | awk -F. '
{ a[$NF]}
END {for (i in a) print i}
' | while read ext junk
do
   cat Report.D${today}*.${ext} > DailyReport.D${today}.${ext}
done

This kinda worked but I could give the files an extension making it unreadable
# 6  
Old 08-24-2016
Hi Jesshelle,
It is great to know that vgersh99's suggestion "kinda worked", but it gives us absolutely no idea what part of it worked and what part of it did not work.

I have tried to get details from you about what you want done, but you did not answer those questions. Let me try once more:
  1. Are you trying to create one file containing all 120 daily reports or are you trying to create five files containing 24 daily reports in each file?
  2. What are the names of the files or what is the name of the file you want your script to create?
  3. Will the filename extensions of the input files always be CTLR, ACCD, BCCD, CCCD, and DDDD, or do the extensions vary from day to day?
  4. If there is one output file (instead of five), are the reports for each filename extension supposed to be grouped together or are the reports for each hour supposed to be grouped together? And, if they are grouped together by extension, does the order in which they appear in the output file matter? And, if so, what is the desired output order?
  5. Will you be running this script on the day the reports are being generated? And, if not, how will your script know what day's reports are to be processed?
  6. What are you using to read the daily report file(s)? Most UNIX system and UNIX-like system tools don't care about the filename extension when reading a text file.

Last edited by Don Cragun; 08-24-2016 at 06:13 PM.. Reason: Fix list.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX and Linux Applications

Concatenation of different reports dynamically

Hi, I have the following reports that get generated every 1 hour and this is my requirement: 1. 5 reports get generated every hour with the names "Report.Dddmmyy.Thhmiss.CTLR" "Report.Dddmmyy.Thhmiss.ACCD" "Report.Dddmmyy.Thhmiss.BCCD" "Report.Dddmmyy.Thhmiss.CCCD"... (1 Reply)
Discussion started by: Jesshelle David
1 Replies

3. Shell Programming and Scripting

Issue in Concatenation/Joining of lines in a dynamically generated file

Hi, I have a file containing many records delimited by pipe (|). Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command awk 'BEGIN {FS="|"} NF !=17 {print}' feedfile.txt... (8 Replies)
Discussion started by: TomG
8 Replies

4. UNIX Desktop Questions & Answers

Combining files with specific patterns of naming in a directory

Greetings Unix exports, I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt They are divided into two sets of test and... (9 Replies)
Discussion started by: A-V
9 Replies

5. Shell Programming and Scripting

Concatenation of two patterns

Read the lines from the file and concatenate the lines into single line then search the string "INPUT=" from the another file and if "INPUT" is present in that file assign the concatenate patterns into "INPUT=" pattern. example: file1.txt <some lines> INPUT = <some lines> file2.txt... (3 Replies)
Discussion started by: krsureshmca
3 Replies

6. UNIX for Dummies Questions & Answers

naming files in awk

I have a whole directory and I need each lines of each file to be separated to a new file but I am facing problem naming them :( some of the files even might be empty the output files should be names original file name + the number of the line or any incremental number FILES="data/*" for X in... (12 Replies)
Discussion started by: A-V
12 Replies

7. Shell Programming and Scripting

Removing Header from files before Concatenation

I need to concatenate the files of same type but with different names that conatin header. Before conactenating its mandatory to remove the header from the files .. and after concatenation the output file should contain header too. how to do it... thanks in advance. (4 Replies)
Discussion started by: amitpta
4 Replies

8. UNIX for Dummies Questions & Answers

naming files that csplit creates

Hi, This is my first time on this forum.. I searched the previous answers, but didn't find the answer I was looking for at first glance. csplit works beautifully for me, except for one thing. My file looks like this: ad|name1|asdf...(several pages)..asdf ... ad|name2|asdf...(several... (8 Replies)
Discussion started by: juliette salexa
8 Replies

9. Shell Programming and Scripting

rowwise concatenation of files

Hi , I am having a file 1n.txt - cat 1n.txt gives get_next_sp_fixing_mod_ref_no, get_next_sp_tran_ref_no, cat 2n.txt - boxer1.cpp boxer2.cpp I want a file resn.txt which has - get_next_sp_fixing_mod_ref_no,boxer1.cpp get_next_sp_tran_ref_no,boxer2.cpp How can i do that ? Its... (3 Replies)
Discussion started by: sid1582
3 Replies

10. UNIX for Advanced & Expert Users

Faster Concatenation of files

Dear All I am using cat command for concatenating multiple files. Some time i also use append command when there are few files. Is there faster way of concatenating multiple files(60 to 70 files) each of 156 MB or less/more.:) Thanx (1 Reply)
Discussion started by: tkbharani
1 Replies
Login or Register to Ask a Question