I have a file named file.txt with contents given below: /href="artifact/com.apple.rrs.app/RRSAdmin/3.2.0.1-SNAPSHOT/RRSAdmin-3.2.0.1-SNAPSHOT.jar">RRSAdmin-3.2.0.1-SNAPSHOT.jar </li></ul></td></tr><tr><td><a></td><td style="vertical-align:middle"><a>No changes.</td></tr></table></td></tr></table><table width="100%"><tr><td id="footer"><span style="padding-right:2em; color:gray"> In this I want to extract only the version number 3.2.0.1 ( which change with the file). I don't want to use command: cut. Also as you can see, the string on both sides of version number is known ( but vary with file) which is available as a variable ($VAR1 and $VAR2). Solution: OK, based on your spec, the version is: 3.2.0.1. var1 is RRSAdmin (the field before the version field if
the field seperator is /)
This awk script should do it: Code: #!/bin/ksh totvar=$(awk ' BEGIN { FS="/" }
# parse the variable string from awk
Have a Linux Problem
Linux Books
Linux Home: Linux System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|