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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:49:12+00:00 2026-06-14T14:49:12+00:00

I am currently trying to use sed to find and replace some text in

  • 0

I am currently trying to use sed to find and replace some text in a file, and for the terms that are being found/replaced, I am trying to use variables, but I cannot get them to work properly for some reason. The variables consist of c1-c9, which can be seen below:

    c1=$( echo "start time;project_start_time" )
    c2=$( echo "start_time;project_start_time" )
    c3=$( echo "end time;project_end_time" )
    c4=$( echo "end_time;project_end_time" )
    c5=$( echo "total time;project_total_time" )
    c6=$( echo "total_time;project_total_time" )
    c7=$( echo "project_id;project_ID" )
    c8=$( echo "status;project_status" )
    c9=$( echo "client_id;client_ID" )
    c10=$( echo "employee_id;employee_ID" )
    c11=$( echo "employee_name;employee_name" )
    c12=$( echo "date created;date_created" )
    c13=$( echo "date_created;date_created" )

and the code that contains the sed part is:

 while [ "$countc" -le 13 ]; do
                    real_string=$( eval echo "\$c$countc" | cut -d ';' -f 2 )
                    nc_string=$( eval echo "\$c$countc" | cut -d ';' -f 1 )
                    sed -e "s/$nc_string/$real_string/gI" phasef/"$count"p.csv #> phasef/"$count".csv
                    countc=$(( $countc + 1 ))
            done

(there is more code to the script, but it is irrelevant) When I run the script, if i tell it to output real_string/nc_string as the while loop moves along, the variables are correctly outputted, real_string/nc_string variables are actually being defined correctly, but I am not sure why sed is not reading them correctly. If anyone could point out what I am doing wrong I would really appreciate it as I have been trying to figure this out for a few hours now, 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-06-14T14:49:13+00:00Added an answer on June 14, 2026 at 2:49 pm

    I checked the echo for “s/$nc_string/$real_string/gI” & it is expanding the variables properly. Please let us know, the input file contents.

    I suspect that, highlited part in below line has some issue.

    sed -e “s/$nc_string/$real_string/gI” phasef/”$count”p.csv > phasef/”$count”.csv

    If you want to replace all pairs in input file (phasef/${count}p.csv) & save to output file (phasef/$count.csv), use below code:

    cp phasef/"$count"p.csv phasef/"$count".csv
    while [ "$countc" -le 13 ]; do
        real_string=$( eval echo "\$c$countc" | cut -d ';' -f 2 )
        nc_string=$( eval echo "\$c$countc" | cut -d ';' -f 1 )
        sed -i -e "s/$nc_string/$real_string/gI"  phasef/"$count".csv
        countc=$(( $countc + 1 ))
    done
    

    Note the -i in sed line.

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

Sidebar

Related Questions

I'm having trouble editing an XML file. I'm currently trying to use Nokogiri ,
currently i'm trying to use imagick to generate some images without saving them on
I am trying to use this command: sed -i 's#\{test1\}#test2#' /example/myfile.txt To replace instances
I'm currently trying to use Quicksand, a jquery plugin that allows you to animate
I am currently trying to use cucumber together with capybara for some integration tests
I'm currently trying to use the core-plot library to graph some data I get
I am currently trying to use two rewrite rules in the .htaccess file in
I am currently trying to use the CloudDrive (Powershell) sample that comes with the
I'm currently trying to use multiple reports so that when a user selects an
I'm currently trying to use a WPF component that makes use of Application.Current from

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.