Increment #'s in text file hourly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Increment #'s in text file hourly
# 8  
Old 06-16-2010
Here is what I have:
Code:
#!/bin/bash

file=BuildManifest.xml
read num < "$file"
printf "%d\n" "versionCode=$(( $versionCode + 1 ))" > "$file"


but I keep getting this error in Terminal
Code:
build.sh: line 5: printf: versionCode=1: invalid number


Last edited by Franklin52; 06-17-2010 at 03:24 AM.. Reason: Please use code tags!
# 9  
Old 06-16-2010
Quote:
Originally Posted by noob33
Here is what I have:

Please put code inside [code] tags.
Quote:
Code:
#!/bin/bash

file=BuildManifest.xml
read num < "$file"
printf "%d\n" "versionCode=$(( $versionCode + 1 ))" > "$file"

but I keep getting this error in Terminal

build.sh: line 5: printf: versionCode=1: invalid number

Is the file in Windows/DOS format with a CR at the end of the line? If so:
Code:
CR=$(printf "\r")
printf "%d\n" "versionCode=$(( ${versionCode%"$CR"} + 1 ))" > "$file"

# 10  
Old 06-16-2010
Quote:
Originally Posted by noob33
Hi, Thank You for all the help so far. The problem I am having is getting this number to increment up by 1. I am not sure if its the "" but it does not seem to work correctly.
versionCode="1" and I need the 1 to increment +1 every time the script runs.
That differs pretty much from your initial request, but here we go: first you'll have to pick the number out between the quotes
(following sed command deletes all but digits):

Code:
read num < "$file"
num=$(echo $num | sed 's/[^0-9]//g')
printf "Versioncode=\"%d\"\n" "$(( $num + 1 ))" > "$file"


Last edited by pseudocoder; 06-16-2010 at 11:06 PM..
# 11  
Old 06-17-2010
Hi Guys, It changed the number. The only problem and I really apologize for not offering more information at the start is it prints the new # and thats it. I have a file with 10 lines of xml code and just wanted to change the version # and it wipes the file and just prints the

VersionCode="2" or whatever number it is at that time

The number changing is perfect Smilie just need it to only change that. Any suggestions?
# 12  
Old 06-17-2010
Can you post your current code which is working (apart from overwriting the input file and only printing VersionCode="2" in it)?
Can you post that 10 lines of xml code (the file that needs to be modified)?

Last edited by pseudocoder; 06-17-2010 at 03:48 AM..
# 13  
Old 06-17-2010
Code:
#!/bin/bash

file=BuildManifest.xml
grep versionCode $file > vercheck.txt
vercheck=vercheck.txt
increase=increase.txt
read num < "$vercheck"
num=$(echo $num | sed 's/[^0-9]//g')
printf "versionCode=\"%d\"\n" "$(( $num + 1 ))" > "$increase"
sed -i 's/$vercheck/$increase/g' $file

Some of the XML:

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:build="http://builds.builds.com"
      package="build"
      versionCode="1"
      versionName="1.0">
    <uses-permission name="build.permission.SEND" />
    <uses-permission name="build.permission.INTERNET" />
    <uses-permission name="build.permission.RECEIVE" />
    <uses-permission name="build.permission.READ_STATE" />


Last edited by Franklin52; 06-17-2010 at 04:05 AM.. Reason: Please use code tags, thank you!
# 14  
Old 06-17-2010
If I got you right, you only want to increase the versioncode number in the xml file, right?
If yes, try this:

Quote:
Originally Posted by noob33
#!/bin/bash

file=BuildManifest.xml
grep versionCode $file > vercheck.txt
vercheck=vercheck.txt
#increase=increase.txt
read num < "$vercheck"
num=$(echo $num | sed 's/[^0-9]//g')
increase=$(printf "versionCode=\"%d\"\n" "$(( $num + 1 ))")
sed -i "s/$vercheck/$increase/g" $file


Some of the XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:build="http://builds.builds.com"
package="build"
versionCode="1"
versionName="1.0">
<uses-permission name="build.permission.SEND" />
<uses-permission name="build.permission.INTERNET" />
<uses-permission name="build.permission.RECEIVE" />
<uses-permission name="build.permission.READ_STATE" />
If it works, then we can talk about unnecessary parts of the script...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining files(every 15 min) as one file(hourly)

Hello, My system is generating two files every 15 minutes and file names are given automatically as below. (98,99,89,90 are the sequence numbers) File1_09242013131016_000000098 File1_09242013131516_000000099 File2_09242013124212_000000089 File2_09242013124712_000000090 I want to combine... (6 Replies)
Discussion started by: phoenex11
6 Replies

2. Shell Programming and Scripting

Increment value in text file

Hi Guys, I am new to shell programing, I have a csv file which has 50k records and I have got the requirement to increment the value in second column after each 5000 records. for example below A,B,C,D //Header 1,1,London,UK 1,1,Manchester,UK 1,1,Glasgow,UK . . . 1,1,Newyork,USA... (7 Replies)
Discussion started by: rizzu1555
7 Replies

3. Shell Programming and Scripting

Increment Numbers in File

Hello, I have a text file withe some records 20121031|5 20121030|3 20121029|1 20121028|4 20121027|6 I want to search for a patten with '20121030' and then increment the second part of the delimiter i.e. 3 by 1 to make it 4 to look like 20121031|5 20121030|4 20121029|1 20121028|4... (7 Replies)
Discussion started by: pparthiv
7 Replies

4. Shell Programming and Scripting

Create log file periodically ex: hourly

Hello, I have a command which runs continuously and creates output to STDOUT. Now, in unix, if I create logging for this command, it would create a single log file and keep on updating. As there is so much data filled in it, I would want to break the log files periodically. In this instance, say... (4 Replies)
Discussion started by: rajkumarme_1
4 Replies

5. Shell Programming and Scripting

FTP a file on Hourly basis

Hi, I have to upload a file test_201105281100.txt to a ftp location. The files will be created on hourly basis like test_201105281100.txt, test_201105281200.txt & so on. After a file is uploaded successfully, I need to rename the file as test_201105281100.success & if it is not uploaded... (11 Replies)
Discussion started by: SunilB2011
11 Replies

6. Shell Programming and Scripting

Increment a value in a configuration file.

Experts, I would appreciate if someone took the time to express there opinion /approach in creating a new change daily to a configuration file. I create a new log file each day and I wish to have a browser based reader display the new file. To achieve this I would need to create a new... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

File existence and increment

count=0; while read line; do ] && let count=count+1; done < file_name.txt echo echo "$count of 10 files found " echo The scenario is a follows : I have a file which contains a list of filenames present in particular directory . I am checking fo the existence of the file and... (5 Replies)
Discussion started by: ultimatix
5 Replies

8. Shell Programming and Scripting

Check file and increment

My scripts excepts 4 files ABCD_01 ABCD_02 ABCD_03 ABCD_04 I want to check for these files , and increment counter one by one . at the end i would like to echo as 4 of 4 expected instances of file found . I tried something like thsi $counter =1 if counter=counter+1 i need... (5 Replies)
Discussion started by: ultimatix
5 Replies

9. UNIX for Dummies Questions & Answers

count string occurance in a file hourly

Hi, I file that has all the status for one day (24hours). Now what I want to do is to count the occurence of a string in its output hourly like for example count occurance of successful or asynchronous clear destinon for every hour and redirect it to file. Please see sample file below. Please... (2 Replies)
Discussion started by: ayhanne
2 Replies

10. UNIX for Dummies Questions & Answers

How do you automate an hourly file check?

Hi, New to the forum, Great site, I can learn a lot from here!! :cool: I would like to know how to automate a command that checks the Sybase database's are "alive" on an hourly basis, and mails outlook if they are not (1 Reply)
Discussion started by: mals
1 Replies
Login or Register to Ask a Question