sed
Sed is a stream editor which modify the copy of original file.Of course we could re-direct the output file to a named result.
Sed syntax: # sed sed_command input_file
the following option are ofen used with sed:
-n : suppress automatic printing and pattern space
There are two ways to query text by using sed: line number and Regular expressions.
print syntax: [address[,address] p
eg: print the 2nd line
# sed -n ‘2p’ test.txt
print the 2nd and 3rd lines
# sed -n ‘2,3p’ test.txt
print the line which match the identified strings:
# sed -n ‘/Yellow/’p test.txt
or # sed -n ‘/Yellow/p’ test.txt
Using mode and line number to query:
line_number,/pattern/ (, is comma)
# sed -n ‘4,/The/’p test.txt
print the last line:
# sed -n ‘$’p test.txt
delete line by using “d”
# sed ‘1d’ test.txt
write the output file created by sed to a new file:
# sed ‘1,2 w new_file’ test.txt
How to know if there are controlling characters in the text? if issue the “# cat -v filename”, the system beeps and there are many stranger characters displaying in the screen, it means the text file has controlling characters.