sed find and replace with curly braces
sed -i ‘s#{test1}#test2#’ /example/myfile.txt You don’t need escape {}
sed -i ‘s#{test1}#test2#’ /example/myfile.txt You don’t need escape {}
here it is sed ‘s/\(.*\)/”\1″/g’
There are two approaches you can try to filter out lines: awk ‘NF’ data.txt and awk ‘length’ data.txt Just put these at the start of your command, i.e., awk -v variable=$bashvariable ‘NF { print variable … }’ myinfile or awk -v variable=$bashvariable ‘length { print variable … }’ myinfile Both of these act as gatekeepers/if-statements. … Read more
The POSIX way awk ‘/pattern1/ || /pattern2/{print}’ Edit To be fair, I like lhf‘s way better via /pattern1|pattern2/ since it requires less typing for the same outcome. However, I should point out that this template cannot be used for logical AND operations, for that you need to use my template which is /pattern1/ && /pattern2/
To print all lines after, and including, the first match: $ echo -ne ‘apple\nbanana\ncherry\n’ | sed -ne ‘/banana/,$ p’ banana cherry To print all lines after, and NOT including, the first match: $ echo -ne ‘apple\nbanana\ncherry\n’ | sed -e ‘1,/banana/ d’ cherry Filtering lines when pattern matches between “text=” and “status=” can be done with … Read more
You can do this with a loop in GNU sed: sed -n ‘/trigger/{p; :loop n; p; /trigger/q; b loop}’ Explanation: When you see the first /trigger/, start a block of commands p — print the line :loop — set a label named loop n — get the next line p — print the line /trigger/q … Read more
bbe is a “sed for binary files”, and should work more efficiently for large binary files than hexdumping/reconstructing. An example of its use: $ bbe -e ‘s/original/replaced/’ infile > outfile Further information on the man page.
Don’t escape the backslashes; you’ll confuse yourself. Use a different symbol after the s command that doesn’t appear in the text (I’m using % in the example below): line_old=’myparam /path/to/a argB=/path/to/B xo’ line_new=’myparam /path/to/c argB=/path/to/D xo’ sed -i “s%$line_old%$line_new%g” /etc/myconfig Also, enclose the whole string in double quotes; using single quotes means that sed sees … Read more
sed -e ‘s/add fast \(pkg\|package\) boots-.*/add yinst pkg boots-5.0/g’ You could always avoid the OR by doing it twice sed ‘s/add fast pkg boots-.*/add yinst pkg boots-5.0/g s/add fast package boots-.*/add yinst pkg boots-5.0/g’
If you are talking about sed, this works: sed -e “s/ /,/g” < a.txt In vim, use same regex to replace: s/ /,/g