Concatenate files to one file with naming convention


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenate files to one file with naming convention
# 1  
Old 02-09-2011
MySQL 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 name is 11021000021.CLT

Thanks in advance.
# 2  
Old 02-09-2011
How about this, should work in bash or ksh

Code:
MAX=0
for file in wrk/[0-9]*.CLT
do
     CNT=${file##wrk/}
     CNT=${CNT%%.CLT}
     [ $CNT -gt $MAX ] && MAX=$CNT
     LIST="$LIST $file"
done
let MAX=MAX+1
cat $LIST > ${MAX}.CLT

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-10-2011
How about this,
Code:
cat *.CLT > 11021000021.CLT

Chubler_XL, I don't understand the reason for the for loop. Could you please explain that?
# 4  
Old 02-10-2011
Quote:
Originally Posted by kurtdriver
How about this,
Code:
cat *.CLT > 11021000021.CLT

Chubler_XL, I don't understand the reason for the for loop. Could you please explain that?
The reason is to determine the next consecutive number.
# 5  
Old 02-10-2011
Ok, if the understand is right.

Code:
Last=$(ls *.CLT|sort -n |tail -1)
let new=${Last%.*}+1            #determine the next consecutive number.
cat *.CLT > $new.CLT

This User Gave Thanks to rdcwayx For This Post:
# 6  
Old 02-10-2011
Quote:
Originally Posted by Franklin52
The reason is to determine the next consecutive number.
Thank you.
# 7  
Old 02-10-2011
Quote:
Originally Posted by Chubler_XL
How about this, should work in bash or ksh

Code:
MAX=0
for file in wrk/[0-9]*.CLT
do
     CNT=${file##wrk/}
     CNT=${CNT%%.CLT}
     [ $CNT -gt $MAX ] && MAX=$CNT
     LIST="$LIST $file"
done
let MAX=MAX+1
cat $LIST > ${MAX}.CLT


Thanks ..it is working fine....but i am telling with current date and number. pls check.

---------- Post updated at 06:15 PM ---------- Previous update was at 06:13 PM ----------

Quote:
Originally Posted by rdcwayx
Ok, if the understand is right.

Code:
Last=$(ls *.CLT|sort -n |tail -1)
let new=${Last%.*}+1            #determine the next consecutive number.
cat *.CLT > $new.CLT


Thanks...out put is 110210021.CLT(means currentdate0021)..Please check
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change the naming convention of the output file

Hi Currently we have nmon running on our Red hat Linux server. The ouput file is now coming with the naming convention as "servername_160321_0010.nmon". The output file naming convention has to be changed as "nmon_servername_daily_2016.03.21_00.00.00" How can we do it ? Any suggestions... (10 Replies)
Discussion started by: newtoaixos
10 Replies

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

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

4. Red Hat

File System Naming Convention

Hi, I am installing a new RHEL 5 application server containing JBOSS along with other specific 3rd party applications. I know that this usually gets installed in /opt but I was thinking of installing these on a new separtate lv / file system instead. i.e. /<my_new_FS_name> rather than... (6 Replies)
Discussion started by: Duffs22
6 Replies

5. UNIX for Dummies Questions & Answers

Check file name against convention

I need this script to check if the first 3 letters of the file name are capital. find . -type f -name *001.dpx -exec find {} ! -name ???_???_???_v??.??????.dpx \; >> ./Bad_FileNames.txt Currently it finds the first frame of the sequence and tests that against the naming convention. It works... (6 Replies)
Discussion started by: scribling
6 Replies

6. Fedora

Basic question regarding rpm naming convention.

Hi Guys, Where would i find the list of distribution codes. For example. samba-32bit-3.4.2 -1.1.3.1.x8664.rpm In above rpm file it is indicated that its release is 1.1.3.1 . The rpm is meant to be run for opensuse. Where would i get the linking of release number and distribution. ... (2 Replies)
Discussion started by: pinga123
2 Replies

7. Hardware

Motherboards naming convention

For the selection of motherboards, is there any naming convention in the type numbers? There is usually a brand name and sometimes a version name, but more essential details like form factor, SATA speed and maximum amount of RAM is never given. Is there a reason for that? Is there any background... (2 Replies)
Discussion started by: figaro
2 Replies

8. Shell Programming and Scripting

Naming convention script

OK, so a quick background: I am a sys admin for a 1:1 deployment in academia with Macbooks, totaling around 6,000. Macbooks get shifted around from building to building and go to and from the repair center if hardware repair is needed. Often, some machines will get moved from one building to... (8 Replies)
Discussion started by: tlarkin
8 Replies

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

10. UNIX Desktop Questions & Answers

Naming convention for Libraries..

Hi All, I need to know standard naming convention for Unix libraries (including all flavours of unix)..As I have gone through some sites and found out The UNIX convention for naming of libraries is lib<name>.so.<major>.<minor>.<revision> so is it statndard . also does it change... (0 Replies)
Discussion started by: rkshukla14
0 Replies
Login or Register to Ask a Question