sed

Remove control chars

For some reason, sed wasn't matching my string variable against another text body which contained the same text. Turns out there were control characters from another encoding type at the end of the string: M-BM-.

cat $var didn't show them, but cat -A $var did. Solution:

$ sed 's/Ctrl+Shift+ua0 (which looks like)
$ sed 's/̲/̲u̲a̲0̲ (to be completed as usual)
$ sed 's/ / /g' mytext.txt

I got this answer from https://askubuntu.com/questions/357248/how-to-remove-special-m-bm-character-with-sed

Delete from start up to and including match:

sed '1,/^WHATEVER$/d'
sed "1,/$my_match/d"

Delete from match to end, including match:

sed '/TAGS/,$d'

Delete range (lines 3 to 5 here)

sed '3,5d' file.txt

Remove duplicate blank lines (but preserve at least one blank line)

'$!N; /^(.*)\n\1$/!P; D' file.txt

Print selected lines (line 5 only in this case)

sed -n '5,5p' file.txt

Get lines before match

sed -n '/_HEADER_/q;p' index.template

Get lines after match

sed -e '1,/_HEADER_/ d' index.template

Wrap HTML element around something

sed 's|www\.[^ ]*|&|g' newtext.html

would wrap around urls starting with www, for example.

Rename files in current dir so that spaces are removed

for f in *\ *; do mv "$f" "${f// /_}"; done
Proxy Information
Original URL
gemini://nuacht.flounder.online/gemlog/2022-07-11-sed.gmi
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
646.144546 milliseconds
Gemini-to-HTML Time
0.424812 milliseconds

This content has been proxied by September (ba2dc).