I want to insert multiple lines into a file. When is do this on a Linux system using:
sed -i "/repositories {/amaven {\n\t\turl 'http://repo1.maven.org/maven2';\n\t}" test
it works fine but fails on Jenkins declarative pipeline with error
+ sed -i /repositories {/amaven {
url http://repo1.maven.org/maven2;
} test
sed: -e expression #1, char 28: unknown command: `u'
This got this resolved using '''.
'''sed -i \"/repositories {/amaven {\nurl \'http:\/\/repo1.maven.org\/maven2\';\n}" test'''
Related
I have a airflow task that I am trying to use sed command for replacing LF with CRLF:
hdfs dfs -cat /test/file.txt | sed 's/$/\r/g' | hdfs dfs -put -f - /test/file.txt
I get following error:
error: sed: -e expression #1, char 4: unterminated `s' command
I think it is due to \r which it is conflicting with. How do I solve this problem?
I found the reason, the \ is a special character in Python.
To solved it I just added an extra \ is it becomes sed 's/$/\\r/g' , another option is to use prefixing.
I am having a issue where i am trying to substitute a variable in sed command while executing it in TCL shell.
Below is what i tried.
set variable 5
exec sed "s/test1\$/test1;test1 $variable/g" file1 > file2
I see below error.
Error: sed: -e expression #1, char 75: unknown option to `s'
Use error_info for more info. (CMD-013)
I have tried some links on stack overflow but that did not help.
Using a Variable in a sed command called in Tcl Script
The general approach is correct. Try this1:
▶ expect
expect1.1> set var /bin/sh
/bin/sh
expect1.2> exec sed -n "s%:$var\$%:/bin/bash%p" /etc/passwd
root:*:0:0:System Administrator:/var/root:/bin/bash
expect1.3> exec sed -n "s%:$var\$%:/bin/bash%p" /etc/passwd > /tmp/log
Analysing your error message:
Error: sed: -e expression #1, char 75: unknown option to `s'
Note that sed received at least 75 characters- far more than in your code example. Does that help you to figure out what went wrong? If not, update with the actual code you tried.
1 Noting that expect just adds some extensions onto TCL, and I don't have TCL on my laptop.
I need to run one input file after another (same folder) and have previously used something along the lines of:
sed -i -e 's/file1/file1/g'
sh run file 1
sed -i -e 's/file1/file2/g'
sh run file 2
However, I recently tried to use this and it wouldn't work. The run file works so I assume I'm just using the sed -i -e command incorrectly?
having trouble with a sed command.
I'm looking to find a line in a file and replace it.
In my script I've used this command without issue; (I use it to set variables)
sed -i '/job=empty/c\job='$job'' $sd/pingcheck-mon-$job.sh
The line I want to replace looks like this,
bash home/user/pingcheck/pingcheck-jobs/job1/pingcheck-mon-job1.sh
This is the command I can't get to run:
sed -i '/bash '$sd'/pingcheck-mon-'$job'.sh/c\jobslot=empty' $wd/pingcheck-worker.sh
Error I get:
sed: -e expression #1, char 9: extra characters after command
Could someone please tell me where I'm going wrong?
Thanks in advance!
I am trying to execute sed command inside TCL script . Basically i wanted to remove all empty lines from the input file before reading the file using TCL. so i tried following in my script
exec sed -i '/^\s*$/d' .tmp.PG_Ring
set fid [open ".tmp.PG_Ring" r]
But the script is dumping following Error .
sed: -e expression #1, char 1: unknown command: `''
while executing
"exec sed -i '/^\s*$/d' .tmp.PG_Ring"
(file "pg_ring.tcl" line 1)
could you please provide me work around for this & help me with best way to do this?
That won't work, as single quotes have no special meaning to Tcl at all. Tcl uses braces to mean the same sort of thing (except they nest nicely), so instead you can use this:.
exec sed -i {/^\s*$/d} .tmp.PG_Ring