How do I convert multi public key into a single line?
tr -d ‘\n’ < key.txt Found on http://linux.dsplabs.com.au/rmnl-remove-new-line-characters-tr-awk-perl-sed-c-cpp-bash-python-xargs-ghc-ghci-haskell-sam-ssam-p65/
tr -d ‘\n’ < key.txt Found on http://linux.dsplabs.com.au/rmnl-remove-new-line-characters-tr-awk-perl-sed-c-cpp-bash-python-xargs-ghc-ghci-haskell-sam-ssam-p65/
For adding a newline after a pattern, you can also say: sed ‘/pattern/{G;}’ filename Quoting GNU sed manual: G Append a newline to the contents of the pattern space, and then append the contents of the hold space to that of the pattern space. EDIT: Incidentally, this happens to be covered in sed one liners: … Read more
As @Didier said, you can change your delimiter to something other than /: grep -rl $oldstring /path/to/folder | xargs sed -i s@$oldstring@$newstring@g
sed ‘:a;/0$/{N;s/\n//;ba}’ In a loop (branch ba to label :a), if the current line ends in 0 (/0$/) append next line (N) and remove inner newline (s/\n//). awk: awk ‘{while(/0$/) { getline a; $0=$0 a; sub(/\n/,_) }; print}’ Perl: perl -pe ‘$_.=<>,s/\n// while /0$/’ bash: while read line; do if [ ${line: -1:1} != “0” … Read more
On Linux, sed -i is the way to go. sed isn’t actually designed for in-place editing, though; historically, it’s a filter, a program which edits a stream of data in a pipeline, and for this usage you would need to write to a temporary file and then rename it. The reason you get an empty … Read more
AWK If you don’t mind using AWK: awk ‘/yahoo/{y=1;next}y’ data.txt This script has two parts: /yahoo/ { y = 1; next } y The first part states that if we encounter a line with yahoo, we set the variable y=1, and then skip that line (the next command will jump to the next line, thus … Read more
The following sed command will work for you, which does not require any capture groups: sed /000/s/^/#/ Explanation: /000/ matches a line with 000 s perform a substitution on the lines matched above The substitution will insert a pound character (#) at the beginning of the line (^)
sed -i ‘s/WORD1.*WORD3/WORD1 foo WORD3/g’ file.txt or sed -i ‘s/(WORD1).*(WORD3)/\1 foo \2/g’ file.txt You might need to escape round brackets, depends on your sed variant.
Here’s a simple example: $ echo ‘abcabcabc’ | sed ‘s/\(ab\)c/\1/’ ababcabc $ echo ‘abcabcabc’ | sed ‘s/\(ab\)c/\1/g’ ababab $ echo ‘abcabcabc’ | sed ‘s/\(ab\)\(c\)/\1d\2/g’ abdcabdcabdc In the first command, only the first match is affected. In the second command, every match is affected. In both cases, the \1 refers to the characters captured by the … Read more
This is easiest using paste: paste -s -d’ \n’ input.txt Although there’s a Famous Sed One-Liner (38) to emulate this as in potong’s answer.