SED

Sed

Change double-spaces to single spaces sed ‘s/ \+/ /g’ > redpine2.txt
Delete all lines in all text files of a directory which follow after the pattern “Retrieved from” find -name ‘*.txt’ -exec sed -i ‘1,/Retrieved from/!d’ {} \;
Display subdirectories in a tree format grep “:$” | sed -e ‘s/:$//’ -e ‘s/[^-][^\/]*\//—-/g’ -e ‘s/^//’ -e ‘s/-/|/’
Generate shuffled list of five-letter words with no repetitions: echo {a,i,o,u}{b,d,f,j,k,l,m,n,p,r,s,t,v,w,z}{a,i,o,u}{b,d,f,j,k,l,m,n,p,r,s,t,v,w,z}{a,i,o,u}|sed ‘s/ /\n/g’| shuf | tr ‘\n’ ‘ ‘
List all the files in a large directory on a single line: ls -1 | sed -e :a -e ‘$!N;s/\n/ \/ /;ta’
List the unique words in a file sed -e $’s/\t//g’ -e “s/[[:punct:]]\+//g” -e “s/./\L&/g” | tr ‘ ‘ \\n | sort | uniq
Prepend an asterisk to every line in a file sed -ne ‘s/.*/* &/p’ enterprise.txt > enterprise2.txt
Remove tags from HTML file sed -e :a -e ‘s/<[^<]*>/ /g;/</{N;s/\n/ /;ba;}’ CleanPosts.html

Batch convert Wordstar-encoded files to text files

#!/bin/bash 
for i in *; 
do strings -a -n 1 "$i" | sed -e :a -e '$!N;s/\n/ /;ta' > "${i%%.*}.txt" 
done

List all the files in a large directory on a single line:

ls -1 | sed -e :a -e ‘$!N;s/\n/ \/ /;ta’

Morse code

#!/bin/sed -rf
s/.*/\U&/
s/$/\nA.-B-...C-.-.D-..E.F..-.G--.H....I..J.---K-.-L.-..M--N-.O---P.--.Q--.-R.-.S...T-U..-V...-W.--X-..-Y-.--Z--../
:a
s/([A-Z])([^\n]*\n.*\1([-.]+))/\3 \2/
ta
s/\n.*//

 

All the words in the Bible that come after “Thou shalt not”

cat kjv.txt | tr ‘[A-Z]’ ‘[a-z]’ | awk -F ‘thou shalt not ‘ ‘NF>1{ sub(/ .*/,””,$NF); print $NF }’ | sed ‘s/punct://g’ | sort | uniq