sedis a non-interactive editor that operates on streams.
sed 's/pattern/replace/' file > new
seddoes not change the contents of the original file. Use
>to send changed output to a new file.
|Range of lines:|
A line specification in
sed can be:
$- the last line
sed 's/hello/goodbye/g' new_file
sed '/foo/,/bar/d' file
sed '/bob/d' data
new_file(but don't change
sed '2,5d' new_file
barin the first 5 lines of file:
sed '1,5s/foo/bar/g' file
sed 's/^ *//'filename
sed 's/ *$//'filename
.matches any character, but
\.matches only the dot itself.
?matches itself, but
\?is a special character
\|can be used to match either of two patterns:
grep 'one\|two' files
diffdescribes the modifications that should be applied to file1 to create file2
% diff file1 file2 2,3c2,3 < this is file1. < it's a lame file. -- > this is file2. > it's a sweet file. 4a5 > maybe not.
filecommand attempts to determine the type of a file:
% file Honda.pdf Honda.pdf: PDF document, version 1.4 % file AdobeFnt.lst AdobeFnt.lst: PostScript document text % file Xrootenv.0 Xrootenv.0: ASCII text, with very long lines % file school/cs553.tgz school/cs553.tgz: gzip compressed data, from Unix % file /bin/bash /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), for GNU/Linux 2.2.5, stripped