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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:18:59+00:00 2026-06-05T10:18:59+00:00

I have a problem with sed command in Shell Script, I have the following

  • 0

I have a problem with “sed” command in Shell Script,

I have the following script to try and replace 3 “labels” with information that I capture from 2 other files:

#!/bin/sh

VAR1=$(cat file1.sh | grep --max-count=1 DLC=)
VAR2=$(cat file1.sh | grep --max-count=1 PROPATH=)
VAR3=$(cat file2.sh | grep -e - )

sed 's|PATTERN1|'"$VAR1"'|' < Template.sh > temp1.sh
sed 's|PATTERN2|'"$VAR2"'|' < temp1.sh > temp2.sh
sed 's|PROGRESS_CONNECTION|'"$VAR3"'|' < temp2.sh > Final.sh

Note that the contents of the 3 vars are strings like (without the double quotes):

VAR1="DLC=/user/aaa/bbb;export DLC"
VAR2="PROPATH=/user/ccc/ddd;export PROPATH"
VAR3="-db docdb -trig triggers -H sona01 -S 19001 -N TCP -ld newyork 
      -db docadm -trig triggers -H sona01 -S 19002 -N TCP -ld docadm 
      -db dochelp -trig triggers -H sona01 -S 19003 -N TCP -ld dochelp 
      -yy 1920 -rereadnolock -T /tmp -c 30 -d mdy -Bt 350 -D 100 -mmax 8192 -nb 200 -s 160 -noshvarfix -inp 32000 
      -cpinternal utf-8 -cpstream utf-8 -cpcoll ICU-UCA"

When I run this script, temp1.sh is correctly created, temp2.sh is correctly created, but Final.sh is not created and I get a sed error message:

sed: -e expression #1, char 91: unterminated `s' command

At this point I am unsure of what is causing the problem.

Any help?

  • 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-05T10:19:00+00:00Added an answer on June 5, 2026 at 10:19 am

    The problem is that your $VAR3 variable does contain some newline characters.

    $ echo "$VAR3"
    -db docdb -trig triggers -H sona01 -S 19001 -N TCP -ld newyork 
          -db docadm -trig triggers -H sona01 -S 19002 -N TCP -ld docadm 
          -db dochelp -trig triggers -H sona01 -S 19003 -N TCP -ld dochelp 
          -yy 1920 -rereadnolock -T /tmp -c 30 -d mdy -Bt 350 -D 100 -mmax 8192 -nb 200 -s 160 -noshvarfix -inp 32000 
          -cpinternal utf-8 -cpstream utf-8 -cpcoll ICU-UCA
    

    A s/// cannot contain a newline (except if preceded by \). A solution would be to remove the newlines with tr -d '\n':

    $ echo "$VAR3" | tr -d '\n'
    -db docdb -trig triggers -H sona01 -S 19001 -N TCP -ld newyork       -db docadm -trig triggers -H sona01 -S 19002 -N TCP -ld docadm       -db dochelp -trig triggers -H sona01 -S 19003 -N TCP -ld dochelp       -yy 1920 -rereadnolock -T /tmp -c 30 -d mdy -Bt 350 -D 100 -mmax 8192 -nb 200 -s 160 -noshvarfix -inp 32000       -cpinternal utf-8 -cpstream utf-8 -cpcoll ICU-UCA
    

    Now use it in sed:

    $ sed 's|PAT|'"$(echo $VAR3 | tr -d '\n')"'|' temp2.sh > Final.sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem. I try to replace a string(well a line) by
I have a problem replacing a command inside of a script, the offending line
I have some problem with replace command. Input file i have this {a[$1]=a[$1]FS$2}END{for(i in
I have a bash shell script that loops through all child directories (but not
I have a BASH/shell script, running on Linux, but it sometimes has a problem
I have a sed command that I want to run on a huge, terrible,
I have a problem with this linux shell script. #! /bin/bash find /sdcard/ -type
i have problem to pass data from view to controller , i have view
I have the following code on my Arduino that constantly checks for a serial
I bumped into the following problem: I'm writing a Linux bash script which does

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.