[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

help with sed syntax

Hiya guys,

I've got this piece of sed code from a bash script, which works great on some versions of sed, and on others it gives errors:

SNC=newfile.conf
sed "/include \"i-lines.conf\"\;/ainclude \"$SNC\"\;" < file.conf > file.conf.tmp

inside file.conf, there is a line with:

include "i-lines.conf";

and after that line, sed should add this line there:

include "newfile.conf";

like I said, it works fine on some sed versions, but on others I get this:

sed: -e expression #1, char 28: Extra characters after command

how can I make this work on all sed versions?
0
HiT5698
Asked:
HiT5698
  • 3
  • 2
  • 2
2 Solutions
 
DonConsolioCommented:
try adding the (missing) closing "/" :-)
(and probably delete the "a" in "ainclude ?)

SNC=newfile.conf
sed "/include \"i-lines.conf\"\;/include \"$SNC\"\;/" < file.conf > file.conf.tmp
0
 
manav_mathurCommented:
sed '/include "i-lines.conf";/ainclude "$SNC";' < file.conf > file.conf.tmp
0
 
HiT5698Author Commented:
I tried the suggestings from both DonConsolio and manav_mathur, but they both still give the same errors :(
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
manav_mathurCommented:
The same seems to work on mine. But again. as you say, it works on some and doesnt work on others. Try (although not much change here)

sed '/include "i-lines.conf";/a\
include "$SNC";' file.conf > file.conf.tmp
0
 
DonConsolioCommented:
probably (with a very old sed) you might need to add a "s" (substitute) before the first "/"

SNC=newfile.conf
sed "s/include \"i-lines.conf\"\;/include \"$SNC\"\;/" < file.conf > file.conf.tmp
0
 
DonConsolioCommented:
CORRECTION:

SNC=newfile.conf
# there has to be a newline after \\ ....
sed  "/include \"i-lines.conf\"\;/a\\
include \"$SNC\"\;" < file.conf > file.conf.tmp
0
 
HiT5698Author Commented:
thanks guys! it's working now ;)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now