generate file incremented by 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generate file incremented by 1
# 1  
Old 08-16-2006
generate file incremented by 1

Hi

I a really need help.
I got simply shell script which store result into the specific file
in this case xxx_001.txt

And after another run script I would like to create the same file but
value 001 is incremented by 1 -> xxx_002.txt a so on.

If I gonna use awk utility then result is not 002 but only 2,
what is wrong.
-------------------------------------------
#!/usr/bin/ksh

file=xxx_001.txt

echo "give me sth" >> $file
------------------------------------------

Thanks

Mape
# 2  
Old 08-16-2006
I don't understand why you need 'awk' and I don't see any 'awk' in your script.
# 3  
Old 08-16-2006
awk is not used in script.
It is a just comment.

But how to solve this problem?
# 4  
Old 08-16-2006
here's an idea - you can take it from here.
Code:
#!/bin/ksh

pivot='/tmp/.fileCount'

typeset -Z3 cnt=1

if [ -f "${pivot}" ]; then
   read cnt < "${pivot}"
fi

echo "cnt->[${cnt}]"
cnt=$(( cnt + 1 ))
echo "${cnt}" > "${pivot}"

# 5  
Old 08-17-2006
perfect job,

its a really work fine.

Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copying a file based on a incremented folder name

I need to routinely cp a file out of the highest incremented folder named PROD_2_6.1_xxx where xxx (3 numerical values) is incremented only once a night starting at 100 and ending 999 over a period of time. I am not worried about copying a subset of a complete file while it is being created by some... (5 Replies)
Discussion started by: sf_cb
5 Replies

2. Shell Programming and Scripting

Environment variable need to be incremented

Dear All, I have created a environment variable say VAR and initialised it to 0.when i do echo $VAR it is showing 0.I have written a shell script with one line VAR=$((VAR+1)) and after running the shell script when i echo $VAR my output is still 0.I want to be 1. when i run the statement... (3 Replies)
Discussion started by: pracheth
3 Replies

3. Shell Programming and Scripting

Needed script to FTP a File and generate a quality checksum file

hi all i want a script to FTP a file and should generate a quality checksum file means when I FTP a file from one server to another server it should generate a QC file which should contain timestamp,no.of records in that file Thanks in advance saikumar (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

4. Shell Programming and Scripting

Replace the content of file with incremented value

I have a file myfile with only one value 1000.I am using it in a shell script.Each time i run the script,the file shud get incremented by 1. I have used the below code for incrementing the value- curr=`cat myfile` echo $curr curr=`expr $curr + 1` But i am not sure how to save this replaced... (2 Replies)
Discussion started by: saga20
2 Replies

5. Shell Programming and Scripting

How to read a delimited string and assign fields to incremented variables?

How can I read a string delimited on spaces and assign the fields to incremented variables. For example: Given $exts= txt dat mov I want to read in $exts and have "txt" "dat" and "mov" assigned to incremented variables like $ext1, $ext2, etc. I would like to do this in a loop so that I can... (4 Replies)
Discussion started by: runit
4 Replies

6. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

7. Shell Programming and Scripting

Perl : how to modify a file without generate a temporary file

Hi All, I have a file like below, how can i insert one line after line 1 without using a temporary file in perl? line 1 line 2 line 3 expected result line 1 new line <---insert here line 2 line 3 (2 Replies)
Discussion started by: summer_cherry
2 Replies

8. Shell Programming and Scripting

How to get the counter value incremented after every 1 min?

I want to check the counter value for every 1 min until the particular counter value is reached and it should exit. Counter value: 15.( For Example) counter = 1 The start time is noted using Localtime. How can i do this in perl? Regards Archana (1 Reply)
Discussion started by: vanitham
1 Replies

9. Shell Programming and Scripting

need help in Parsing a CSV file and generate a new output file

Hi Scripting Gurus, I am trying to parse a csv file and generate a new output file. The input file will be a variable length in turns of rows and columns. output file will have 8 columns. we have three columns from the header for each set. just to give little bit more clarification each row... (15 Replies)
Discussion started by: vkr
15 Replies

10. UNIX for Dummies Questions & Answers

Script to generate text file from excel file

Hello, I have a excel file which has almost ten columns on the shared drive. I have to write a shell script to ftp that daily to unix server and then extract some columns from there and generate oracle standard text file. The columns should be in proper order and aligned properly, otherwise... (1 Reply)
Discussion started by: isingh786
1 Replies
Login or Register to Ask a Question