back

Bash Commands: sed

To delete blank lines in a file1:

sed -i '/^$/d' fileName sed -i '/^ *$/d' fileName

To change lowercase letters to uppercase:

sed -i 's/.*/\U&/' fileName

To comment all lines in a file1:

sed -i 's/^\([^#]\)/#\1/g' fileName

To uncomment all lines in a file:

sed -i 's/^#//g' fileName

To replace newline with a comma:

~/Documents/00__tmp/binary_table/scratch$ cat sed__bitRow.txt 
"bv128"
"bv64"
"bv32"
"bv16"
"bv8"
"bv4"
"bv2"
"bv1"

~/Documents/00__tmp/binary_table/scratch$ cat sed_loop.sh
#!/bin/bash

# bash ./sed_loop.sh 

sedLoop() {
	sed -i -e '{
	N
	s/\n/,/
	}' sed__bitRow.txt
}

for (( i=1; i<=3; i++ ))
do
	#echo "$i"
	sedLoop
done	

cat sed__bitRow.txt

exit

~/Documents/00__tmp/binary_table/scratch$ bash ./sed_loop.sh 
"bv128","bv64","bv32","bv16","bv8","bv4","bv2","bv1"

Footnotes

1. http://otaqui.com/blog
2. ibid