HELP !! Builting string in incremental order


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting HELP !! Builting string in incremental order
# 1  
Old 08-11-2006
HELP !! Builting string in incremental order

I have files in a folder like ..

citi11082006_1.trn
citi11082006_2.trn
citi11082006_3.trn
...
...
...
citi11082006_13.trn
.,...
citi11082006_nn.trn

Each file will have one string inside and I am builting a master string based out the string in the sub files by merging all into one by script.

I am merging the file into one master file into a string and name should be
citi11082006.trn

my script is like:
Code:
#!/bin/ksh
export TSTAMP=`date +"%d%m%Y"`
cd /export/home/xxx/
count=$(ls citi${TSTAMP}_*.trn | wc -l)
echo "file appending"
count=$(ls citi${TSTAMP}_*.trn | wc -l)
cat citi${TSTAMP}_*.trn | tr -d '\n' > citi${TSTAMP}.trn
chmod 777 citi${TSTAMP}.trn
echo "FILE MERGE SUCCESSFULLY..."
rm -f citi${TSTAMP}_*.trn


There is additional element called END always present in lats file and thus while merging one of builting a string.
This works fine when subfile has 9 in numbers.


This does not work when file have more than 9 in numbers thus unforced to built a wrong string.

Is there any way to bulit a string so that elements of citi11082006_2.trn always come after citi11082006_1.trn and so on...

like wise string citi11082006_13.trn will come after citi11082006_12.trn.

The above is not working in incremental order, as 10 comes after 1 and then 11.
Can any one help me what is best way to get a string in incremental order.
thanks in advance
regards
# 2  
Old 08-11-2006
Here's a thought. Since those are generated sequentially, you might as well try the -t flag for ls.

Try this.

Code:
for file in $(ls -t citi${TSTAMP}_*.trn)
do
cat $file | tr -d '\n' > citi${TSTAMP}.trn
done

for the line

Code:
cat citi${TSTAMP}_*.trn | tr -d '\n' > citi${TSTAMP}.trn

Not tested.
# 3  
Old 08-11-2006
Another way :

Code:
Prefix=citi${TSTAMP}
for file in $(ls ${Prefix}_*.trn | sort -k1.$((${#Prefix}+2))n)
do
   tr -d '\n' < $file >> $Prefix.trn
done

EDIT --
Correction of suffix for filenames (.DAT replaced by .trn)
Correction of redirect operator (> replaced by >>)


Jean-Pierre.

Last edited by aigles; 08-14-2006 at 06:44 AM..
# 4  
Old 08-14-2006
-t flag for ls not working ..

Vino,

I just found the script only display the 9th number file, in the group of 11, any other thoughts
# 5  
Old 08-14-2006
aigles,

I have tried your code also, but it would only showing the last data of last file ,

Code:
Prefix=citi${TSTAMP}
for file in $(ls ${Prefix}_*.DAT | sort -k1.$((${#[Prefix]}+2))n)
do
   tr -d '\n' < $file > $Prefix.trn
done

is there any other thoughts

Last edited by u263066; 08-14-2006 at 06:44 AM..
# 6  
Old 08-14-2006
try with the corrected version of the script (see my previous post)

Jean-Pierre.
# 7  
Old 08-14-2006
thanks

i was missed >> in my code.

Thanks a ton...

its works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Incremental logic

Hi Guys, am trying to write logic to do incremental value using linux Example: a=00.00.00.01 My b should be like this b=00.00.00.02 and when it reaches 99 my b should look like this b=00.00.01.99 Appreciate your help guys Please use CODE tags when displaying sample input, sample... (14 Replies)
Discussion started by: buddi
14 Replies

2. Shell Programming and Scripting

sed string with any order

Hi, i have a strange prob. log file contains ip, protocol, user name, agent . these can be in any order. If log contains the above order able to fetch all details but if details are in diff order not able to fetch all details. using below command. grep -A50 "Entry " "/logs/file.log" \ |grep... (6 Replies)
Discussion started by: Satyak
6 Replies

3. Shell Programming and Scripting

Manipulate XML File Continous STRING by each Order Line using SHELL

heres sample File: <?xml version="1.0"?> <!DOCTYPE cXML SYSTEM "www"><cXML.............................................. <OrderRequest>USE UNIX.com</Extrinsic><Extrinsic name="UniqueName">Peter@UNIX.com</Extrinsic><Extrinsic name="ContractingEntity">UNIX... (3 Replies)
Discussion started by: Pete.kriya
3 Replies

4. Shell Programming and Scripting

Swapping a string of numbers between higher and lower order values(HEX)

I have this below string in a variable cutString=21222222222222222122222222222222 this string is nothing but hex values depicted as below 21:22:22:22:22:22:22:22:21:22:22:22:22:22:22:22 so what i want to achieve is swap the lower order with higher order values in the... (3 Replies)
Discussion started by: vivek d r
3 Replies

5. Shell Programming and Scripting

print in incremental order a sentence

Dear help! I want to print The number i is number i let i=1 to 5 output should be like The number 1 is number 1 The number 2 is number 2 The number 3 is number 3 The number 4 is number 4 The number 5 is number 5 Would be gr8 if you mke this with awk Thanks (7 Replies)
Discussion started by: Indra2011
7 Replies

6. Shell Programming and Scripting

Finding a String and Replacing it with an incremental value

Hi Friends, I have a text file which has about 200,000 records in it. we have a string which repeats in each and every record. So we have to write a script in ksh which finds that string on each line and replaces it with a new string(incremental value) for a set every four records. To be... (12 Replies)
Discussion started by: vpv0002
12 Replies

7. UNIX for Dummies Questions & Answers

incremental by 1

let says, i have this number as 000002080, i want to add 1 to make it 000002081, and then i want to add 1 to 000002082, add 1 to 000002083, 84. i=000002080 TOT=$(echo "scale=9; $i + 1" | bc) echo $TOT it shows 2081, i want to retain 000002081, 000002082, 000002082, 000002084. (2 Replies)
Discussion started by: tjmannonline
2 Replies

8. Shell Programming and Scripting

Incremental backup

Hi, I would like to create a daily incremental backup of a directory with all of the files within and add a timestamp (year-month-day) to the tar.gz file. I have the following, but it doesn't backup the inside files of the directory. #!/bin/bash tar -czf... (1 Reply)
Discussion started by: agasamapetilon
1 Replies

9. UNIX for Dummies Questions & Answers

How to change the order of a string ?

Hi , I want to change the order of a string using sed command . Is it possible ? $echo "abc123xyz" | sed 's/\()*\) \(*\)/\2\1/' abc123xyz $ echo "abc123xyz" |sed 's/\()*\) \(*\) \()*\)/\2\1\3/' abc123xyz I want to change the string , abc123xyz as xyz123abc . Is it... (5 Replies)
Discussion started by: rajavu
5 Replies

10. Shell Programming and Scripting

output string in reversing order

If I have string { I_love_shell_scripts} anyone knows how to have output {stpircs_llehs_evol_I} by using shell and perl ?I know in perl, there is reverse() funcation, but can it be done by not using reverse()? (3 Replies)
Discussion started by: ccp
3 Replies
Login or Register to Ask a Question