LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-05-2020, 10:48 AM   #1
igagankalra
LQ Newbie
 
Registered: Jun 2020
Posts: 1

Rep: Reputation: Disabled
sed command unterminated 's' command


I'm trying to replace a connection String in a yml file.

The command which gets populated with variables is
Code:
sed -i 's^\<constring\>\s*:.*^contring : \['1\|\|sS3kEuT24A1rE3hT5U_fWcYJa4y7KxmgJYYg5Ms8eBxRqMvphym7sz4M-Wmdt5AMbsrELTxW7Ng1U4mDRms0_JQ3LIqppYm8qb1k57_MeOv7LPU20v7pYyNPakDBf0mL1JixPIGk7oUGAZwfQCnSrqzhSDGz-7jek6wPWXMVq13_6pbUJSoo1J-mD5NwfKvqBHRZeJzaIuCenqv7KuWST9VrgIc6ZKAm3CLKC5Gb2gT5lnnqlGG373reml6KaIev7j0UbFecbKfWBY7A==, logs', '1\|\|hlt81VYLBRFCQnhCi1dGxci3-GCnBoe2Ke_qZ7LX7BIZEBYWNzWcuO9FhaW3XqpC_NskrD4RGe3ApyRBu4Rm-cIqqolP9aMt9h56W-TtMxWDXpja6h-aAzYmed51aAVP_jMRd_zarI0jbHfzlENWfpTJlSzDaxV4NJJNgCgCW2cDKoH4vqC8CwxxHpL_LKo8HkS13ZoyDpVsuAUYlwiBj5xmsPlXPwfQBTqoZxVFCGq18vWB7zpXaZ6W09wSS=, log1'\]^gi' file.yml
I have tried it without escaping pipe(|) and even Square brackets([)
But nothing works.

Error after running this command -- sed: -e expression #1, char 327: unterminated `s' command


Please help
 
Old 06-05-2020, 11:02 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,303
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
Welcome.

It looks like a matter of quotes. Use double quotes for the outermost set.

However, what are you actually trying to do with sed? If the content of the file is structured then something capable of parsing the format would be more appropriate.
 
2 members found this post helpful.
Old 06-05-2020, 01:37 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
First, as Turbocapitalist said above it's matter of quoting. The space between green and red is not quoted. Neither is the space between red and magenta. Everything after the first unquoted space is considered by sed to be file names.
Code:
sed -i 's^\<constring\>\s*:.*^contring : \['1\|\|sS3kEuT24A1rE3hT5U_fWcYJa4y7KxmgJYYg5Ms8eBxRqMvphym7sz4M-Wmdt5AMbsrELTxW7Ng1U4mDRms0_JQ3LIqppYm8qb1k57_MeOv7LPU20v7pYyNPakDBf0mL1JixPIGk7oUGAZwfQCnSrqzhSDGz-7jek6wPWXMVq13_6pbUJSoo1J-mD5NwfKvqBHRZeJzaIuCenqv7KuWST9VrgIc6ZKAm3CLKC5Gb2gT5lnnqlGG373reml6KaIev7j0UbFecbKfWBY7A==, logs', '1\|\|hlt81VYLBRFCQnhCi1dGxci3-GCnBoe2Ke_qZ7LX7BIZEBYWNzWcuO9FhaW3XqpC_NskrD4RGe3ApyRBu4Rm-cIqqolP9aMt9h56W-TtMxWDXpja6h-aAzYmed51aAVP_jMRd_zarI0jbHfzlENWfpTJlSzDaxV4NJJNgCgCW2cDKoH4vqC8CwxxHpL_LKo8HkS13ZoyDpVsuAUYlwiBj5xmsPlXPwfQBTqoZxVFCGq18vWB7zpXaZ6W09wSS=, log1'\]^gi' file.yml
Second, using ^ to quote pattern for the s command is unwise and confusing because ^ has a special meaning in RE: anchor for the start of line.

Third, if it's YAML then parse it with yq rather than with sed.
 
1 members found this post helpful.
Old 06-06-2020, 03:21 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
In the replacement string you must escape
  • the shell string delimiter ' so each ' with a '\''
  • the separator ^ so each ^ with a \^
  • the match reference & so each & with a \&
  • the escape character \ so each \ with a \\

Last edited by MadeInGermany; 06-14-2020 at 11:32 AM. Reason: typo
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed: -e expression #1, char 137: unterminated `s' command redd9 Linux - Software 5 04-02-2020 10:13 PM
[SOLVED] sed: -e expression #1, char 57: unterminated `s' command TashiDuks Programming 9 12-13-2016 11:33 PM
SED command failing while substituting variable with error unterminated `s' command vnarvankar Linux - Software 2 03-10-2016 09:10 AM
[SOLVED] sed unterminated `s' command random0munky Linux - Newbie 7 08-19-2011 11:43 AM
sed: Unterminated 's' command whatis Programming 2 11-02-2009 02:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration