Posts

Showing posts with the label sed

Removing tags in html (and similar) files

sed - e 's/<[^>]*>//g' file . html

Batch rename files

When renaming a number of files at the same time, it is more convenient to use a GUI for the job. Métamorphose is one such program that does the job brillianty, and freely. There are others Flash Renamer was another (not free) great program. However, sometimes it is fun to do the same stuff using command-line. Below are a couple of ways to do batch renaming.

Count number of lines in a file

The following counts the number of lines in a given file: sed -n '$=' NAP_Books.txt

Delete lines based on a length limit

The following command deletes lines which have less than 10 characters. sed '/.\{10\}/!d'

Remove the First N Characters From a Line

The following codes remove first 6 characters. Change the number accordingly... cut -c7- ' this works rr ^.{6} ' rr was not installed colrm 1 6 rr s/^.{6}// sed's/^.\{6\}//' perl -pe's/^.{6}//' ruby -pe'sub /^.{6}/,""' gawk'BEGIN{FIELDWIDTHS="6 999"}{print$2}'

Batch Renaming

If you need to rename a bunch of files from, for example,|add.png| to|add_32.png|, just do the following: for i in *; do j=`echo $i | cut -d . -f 1`; j=$j"_32.png"; mv $i $j; done