Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write output to file 1

Status
Not open for further replies.

ryanewing

Technical User
Aug 15, 2007
4
US
Hey all, I am trying to write a script that will take a mask in, such as

+.*.*.*

which will run on a text file containing only a version number, like:

1.0.0.0

and will update the text file according to the mask. The output should be

2.0.0.0.

AND IT IS. But putting the result on the screen is the farthest I've gotten. I don't know how to write this back into a file. I'm sure its simple. I am totally new to the command line.

version.awk:


BEGIN { FS="." }

first = $1
second = $2
third = $3
fourth = $4
fifth = $5

getline < "cmdver.txt"
{if ($1=="+") $1=first + 1
else if ($1=="[0-9]*") $1=$1
else $1 = first}

{if ($2=="+") $2=second+1
else if ($2=="[0-9]*") $2=$2
else $2 = second}

{if ($3=="+") $3=third+1
else if ($3=="[0-9]*") $3=$3
else $3 = third}

{if ($4=="+") $4=fourth+1
else if ($4=="[0-9]*") $4=$4
else $4 = fourth}

{print $1,".",$2,".",$3,".",$4}




version.bat:


Echo %1 > cmdver.txt
gawk -f version.awk %2


Any tips? And a very minor problem at the moment; if a number is entered instead of a star or +, the output doesn't change, and it is supposed to.
 

Try re-directed output:

Code:
gawk -f version.awk %2 >resultFile.txt
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
That works. Is there a way to re-direct it back into the original version file ver.txt? When I try that, I end up with a blank text file.

Also, there are three lines that are produced and I only want the last one, how should I grab that?
 
No editing posts?

My only problems now are being able to write to the file I started with and probably the most important is being able to replace with numbers..

8.0.0.0
*.5.3.0

shoud give me

8.5.3.0
 
Really sorry to Triple-post, but I keep figuring new things out on my own.

My only problem is replacing with a number if one is given.

8.0.0.0
*.5.3.0

shoud give me

8.5.3.0

Any help would be greatly appreciated.
 
I'm curious as to why you're effectively writing your own regular expression language/interpreter when there are already powerful ones in existence? Is it purely because you need the mathematical capability, i.e. to increment a version number?

Otherwise, I think the only problem is that you can't use == to compare a value to a regexp, you need to use ~, e.g.

[tt]$4=="[0-9]*"[/tt]

becomes:

[tt]$4~/[0-9]+/[/tt]

I also changed * to +, i.e. meaning one-or-more digits rather than zero-or-more.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top