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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on unix

Status
Not open for further replies.

311397

Programmer
Aug 18, 2000
4
US
hi ,
my problem is i am writing some shell scripts.
so i have to get a string from a text file.
i would like to explain clearly
eg1.txt is a text file. it contains the information like below
VERSION=1.00.00

actually this information(result) came from anothr binary file which is redirected to eg1.txt file.so from this file
i have to extract only the part ie 1.00.00 ie,
i need only that number.
the above one is the entire field. ie
VERSION=1.00.00 just it is the field in some file.

please give me the response
 
IF you just want to catch the version number as output from the original program, try this:
[tt]
VERSION=`original_program | grep "^VERSION=" | sed -e 's/^VERSION=//'`
[/tt]
This will place "1.00.00" into the environment variable $VERSION, and you can do whatever you want with it from there.

If you wanted to grab the version number from a text file, you could try:
[tt]
VERSION=`grep "^VERSION=" somefile.txt | sed -e 's/^VERSION=//'`
[/tt]

Hope this helps.
 
311397,

You could pipe the file through 'cut' like so:

[tt] cut -f2 -d&quot;=&quot; < eg1.txt > eg1.out[/tt]

This would cut field number 2 delimited by the = character and put it into the output file.

Annihilannic.
 
i got a problem that is concerned to my previous question

i had a file ie, relnum which contains only the release no
like 1.00.444
so every night the number should be incremented
this no is comming from another file. ie, suppose
today release no is 1.00.444 it will be stored in
pkginfo file. tomorrow the rel no is 1.00.445

problem is for me input to the pkginfo file is relnum
as i explained relnum has just 1.00.444
so how i can increase that number by every night
can we use field seperators ,
give me the solutions
Thanks with regards

 
Try this:
[tt]
VERSION=1.00.444

REL=`echo $VERSION | cut -d&quot;.&quot; -f1`
SUBREL=`echo $VERSION | cut -d&quot;.&quot; -f2`
SUBVER=`echo $VERSION | cut -d&quot;.&quot; -f3`

SUBVER=`expr $SUBVER + 1`

VERSION=&quot;${REL}.${SUBREL}.${SUBVER}&quot;
[/tt]

I've not had chance to test it, but that should work OK. Anyone want to come up with an awk version? ;^)
 
AndyBo,

Okay:

[tt] NEWVERSION=`echo $VERSION | awk 'BEGIN { FS=&quot;.&quot; } { print $1 &quot;.&quot; $2 &quot;.&quot; $3+1 }'[/tt]

This awk solution redefines the field separator (FS) as '.', and then reprints the version with the third field ($3) incremented by 1.

Annihilannic.
 
Excellent! Thanks for that, Annihilannic! I *always* forget about the &quot;FS&quot; variable :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top