Sed
From UC_Chemistry
[edit]
Some commands
Suppose we have file input file inputfile. Here is the list of some usage of sed
Count number of lines in file (we actually print the number of the last line)
sed -n '$=' inputfile
Print everything between 'pattern1' and 'pattern2' (every pattern must be enclosed in two forward slashes)
sed -n '/pattern1/,/pattern2/p' inputfile
Delete all lines containing "text" ( d is for deletion of line)
sed '/text/d' inputfile
Delete just the word "text" (we actually substitute text with nothing)
sed 's/text//g' inputfile
Print everything from 'starthere' till the end of file. $ is a symbol to indicate last line in file and p says to print the line.
sed -n '/starthere/,$p' inputfile
Replace pattern1 with pattern2 (without option g it will replace only first instance of pattern1 in each line)
sed 's/pattern1/pattern2/g' inputfile
[edit]
