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 6997771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:19:31+00:00 2026-05-27T20:19:31+00:00

I am trying to search for a text in a file and store it

  • 0

I am trying to search for a text in a file and store it into a variable.

My file looks something like this:

Type: Furniture
Color: Blue
Version: 1

I am trying to search for the Version number and store it into a variable and increment it. This number is unknown to me when I am searching the file. So far I have something like this.

VERSIONNUMBER=//Somehow I want to get the version # from the file. 
VERSIONNUMBER=`expr $VERSIONNUMBER + 1'

sed -i "s/Version:.*/Version=$VERSIONNUMBER/" filename

Am I on the right track so far or is there a better way of doing this? I’m having trouble searching for the version number. I keep getting syntax errors. Any help is much appreciated.

VERSIONNUMBER=`sed -i "s/Version:/*" filename`
  • 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-27T20:19:32+00:00Added an answer on May 27, 2026 at 8:19 pm

    This is a job for awk

     awk '/Version:/{$2++}1' ./infile > ./outfile
    

    Example

    $ awk '/Version:/{$2++}1' ./infile
    Type: Furniture
    Color: Blue
    Version: 2
    

    Explanation

    /Version:/ Match only lines that contain the text ‘Version:’

    $2++: Get the 2nd field, of which awk delimits with a space by default, and increment it

    {...}1: A shortcut to tell awk to print out the lines after it does any alterations

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to search a text file for a certain pattern. If this
Here is an example of the type of text file I am trying to
I'm a rookie trying to search a text file for some serial numbers. I'm
Im trying to search through a text file and find the valid email addresses.
I'm trying to write a perl script to search through a text file, find
I'm trying to use the search text box (which I made by following this
I am trying to get filtered list of all Text and Python file, like
I am trying to put full text search working on SQL Server 2008, however
I am trying to add full text search capabilities to my RoR app, but
I am trying to full text search a column, but also be able to

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.