sed + remove “#” and empty lines with one sed command

If you’re worried about starting two sed processes in a pipeline for performance reasons, you probably shouldn’t be, it’s still very efficient. But based on your comment that you want to do in-place editing, you can still do that with distinct commands (sed commands rather than invocations of sed itself). You can either use multiple … Read more

Split string with bash with symbol

Using Parameter Expansion: str=”test1@test2″ echo “${str#*@}” The # character says Remove the smallest prefix of the expansion matching the pattern. The % character means Remove the smallest suffix of the expansion matching the pattern. (So you can do “${str%@*}” to get the “test1” part.) The / character means Remove the smallest and first substring of … Read more

Printing verbose progress from sed and awk

This is based on potong’s answer. The following code replaces ‘ll’ with ‘zz’, creates a backup file, displays the new text, and writes the change(s) into the file. $ echo hello > test $ sed -e ‘s/ll/zz/;w /dev/stdout’ -i .backup test hezzo $ cat test hezzo $ cat test.backup hello