What is sed
A stream editor
Syntax
sed [-n ] Script [ File ...]
e.g. sed -n 1p /some/file/name.txt > test.txt
sed [-n ] [-e Script ] ... [-f ScriptFile] [ File ...]
For example, with the script sed -e '1d' my/input/file
>my/output/file, you could put
'1d' in a file known as MyScriptFile, and then it will appear as:e.g. sed -n 1p /some/file/name.txt > test.txt
sed [-n ] [-e Script ] ... [-f ScriptFile] [ File ...]
sed -e -f MyScriptFile my/input/file >my/output/file
-------MyScriptFile-----------
1d
---------------------------------
Note that commands are _without_ quotes int his file!
Few sed examples:
Print only the first line of a file
sed -n 1p /some/file/name.txt > test.txt
Print only the 2nd line of a file
sed -n 2p
/some/file/name.txt
>test.TXT
Start copying from
first line and end at third:
sed -n 1,3p
/some/file/name.txt
>test
Delete line number 1
and then write it to the output…could be helpful in cases, e.g. where you like
to delete the header from a SQL output
sed -e '1d' my/input/file
>my/output/file
No comments:
Post a Comment