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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:53:10+00:00 2026-06-17T11:53:10+00:00

I have a text file with lines like this: variable_name : value I need

  • 0

I have a text file with lines like this:

  variable_name : value

I need to make a bash script to replace “value” with a fixed value I know (let say “myvalue”).

I don’t know previously which is the variable_name’s value.

I need to use bash commands that can be used in any default installation of linux box like sed, grep, awk, etc.

I know how to do it with sed when I know the “value” string, but I can’t figure out how to do it by searching in the file by the name of the variable.

EDIT: I add some complexity to this task, I have to exclude some patterns with a fixed text, for example if I have:

  variable_name : value
  variable_name : VARIABLE_NAME > lorem_ipsum

I have to exclude the replacement with the string VARIABLE_NAME. The result must be:

  variable_name : myvalue
  variable_name : VARIABLE_NAME > lorem_ipsum     

Thanks in advance,

  • 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-06-17T11:53:11+00:00Added an answer on June 17, 2026 at 11:53 am

    are you looking for this?

    echo "variable_name : value"|sed -r 's/(variable_name :)(.*)/\1myvalue/'
    variable_name :myvalue
    

    EDIT for new requirement

    you said you will exclude replacement with string VARIABLE_NAME, so I assume that (space)> lorem_ipsum will be replaced by new value.

    so this line may help:

    awk 'BEGIN{v="variable_name";V=toupper(v); FS=OFS=" : "} $1~"^"v{$2=($2~"^"V)?V"myValue":"myValue"}1' file
    

    take a look this:

    kent$  echo "variable_name : value
    variable_name : VARIABLE_NAME > lorem_ipsum"|awk 'BEGIN{v="variable_name";V=toupper(v); FS=OFS=" : "} $1~"^"v{$2=($2~"^"V)?V"myValue":"myValue"}1';                         
    variable_name : myValue
    variable_name : VARIABLE_NAMEmyValue
    

    EDIT2

    Neuquino, you should explain your requirement more clear….. anyway:

     kent$  echo "variable_name : value
    variable_name : VARIABLE_NAME > lorem_ipsum"|awk 'BEGIN{v="variable_name";V=toupper(v); FS=OFS=" : "} $1~"^"v && $2!~"^"V{$2="myValue"}1';                                  
    variable_name : myValue
    variable_name : VARIABLE_NAME > lorem_ipsum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have a text file that is organized like this <username>:<fullname>:<usergroups> I need
if I have a text file like this : this is line one This
I have a huge text file with lines like: -568.563626 159 33 -1109.660591 -1231.295129
I have a huge text file with lots of lines like: asdasdasdaasdasd_DATA_3424223423423423 gsgsdgsgs_DATA_6846343636 .....
I have a huge text file with lots of lines like: a 23232 23232
I have 100 text files which look like this: File title 4 Realization number
I have a large (~100GB) text file structured like this: A,foobar A,barfoo A,foobar B,barfoo
I have a perl script creates a text file, writes captured lines from a
I have text file with something like first line line nr 2 line three
I have a text file which has a particular line something like sometext sometext

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.