I have a text file with a number "001". I am trying to change this number every hour and increment by "1". So every hour it would add +1 to that number. I am able to change the file with sed but unable to have it increment it by "1" without me adding that to the sed command. Any help is appreciated.
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):
read num < "$file"
num=$(echo $num | sed 's/[^0-9]//g')
printf "Versioncode=\"%d\"\n" "$(( $num + 1 ))" > "$file"
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 just need it to only change that. Any suggestions?
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)?
It does not seem to be working. I looked in the vercheck.txt and it shows the version. The only thing is and I am not sure if this makes a difference but it has a lot of spaces:
android:versionCode="1"
Thanks again for the help this forum really is awesome.
---------- Post updated at 02:10 AM ---------- Previous update was at 02:06 AM ----------
It does not seem to be changing the versionCode #.
Okay, can you try this (as you see I removed the last sed command, to see if the other parts work properly)?
If you are satisfied with the output of echo $increase then we can fully concentrate on the sed part.
Until now, in the $vercheck variable there was the filename (vercheck.txt) stored, and not the actual string that needs to be replaced.
That might have been the failing point.
Did you get any error message?
Can you please double check that you have correctly copy/pasted my latest posting (incl. some changes that I had to do right after I've posted that).