Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3936700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:58:46+00:00 2026-05-19T23:58:46+00:00

I need to get a particular version string from a file (call it version.lst)

  • 0

I need to get a particular version string from a file (call it version.lst) and use it to compare another in a shell script. For example sake, the file contains lines that look like this:

V1.000 -- build date and other info here -- APP1
V1.000 -- build date and other info here -- APP2
V1.500 -- build date and other info here -- APP3

.. and so on. Let’s say I am trying to grab the first version (in this case, V1.000) from APP1. Obviously, the versions can change and I want this to be dynamic. What I have right now works:

var = `cat version.lst | grep " -- APP1" | grep -Eo V[0-9].[0-9]{3}`

Pipe to grep will get the line containing APP1 and the second pipe to grep will get the version string. However, I hear grep is not the way to do this so I’d like to learn the best way using awk or sed. Any ideas? I am new to both and haven’t found a tutorial easy enough to learn the syntax of it. Do they support egrep? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:58:47+00:00Added an answer on May 19, 2026 at 11:58 pm

    Try this to get the complete version:

    #!/bin/sh
    app=APP1
    var=$(awk -v "app=$app" '$NF == app {print $1}' version.lst)
    

    or to get only the major version number, the last line could be:

    var=$(awk -v "app=$app" '$NF == app {split($1,a,"."); print a[1]}' version.lst)
    

    Using sed to get the complete version:

    var=$(sed -n "/ $app\$/s/^\([^ ]*\).*/\1/p" version.lst)
    

    or this to get only the major version number:

    var=$(sed -n "/ $app\$/s/^\([^.]*\).*/\1/p" version.lst)
    

    Explanations:

    The second AWK command:

    • -v "app=$app" – set an AWK variable equal to a shell variable
    • $NF == app – if the last field is equal to the contents of the variable (NF is the number of field, so $NF is the contents of the NFth field)
    • {split($1,a,".") – then split the first field at the dot
    • print a[1] – and print the first part of the result of the split

    The sed commands:

    • -n – don’t print any output unless directed to
    • "/ $app\$/ – for any line that ends with (\$) the contents of the shell variable $app (not that double quotes are used to allow the variable to be expanded and it’s a good idea to escape the second dollar sign)
    • s/^\([^ ]*\).*/\1/p" – starting at the beginning of the line (^), capture \(\) the sequence of characters that consists of non-spaces ([^ ]) (or non-dots in the second version) of any number (zero or more *) and match but don’t capture all the rest of the characters on the line (.*), replace the matched text (the whole line in this case) with the string that was captured (the version number) (\1 refers to the first (only, in this case) capture group, and print it (p)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to get the color at a particular coordinate from a texture. There
I need to get all characters between a particular expression. For example below is
I need to get the Vector Space Model(with tf-idf weighting) from the results of
I'm working with C#.net developing applications for windows mobile 6, and i need get
I need to get the default printer name. I'll be using C# but I
I need to get a log of user access to our SQL Server so
I need to get the first and last day of a month in the
I need to get some information that is contained in the MFT on a
I need to get the name of the machine my .NET app is running
I need to get the value of the 'test' attribute in the xsl:when tag,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.