CS155 Commands3
sed
is a non-interactive editor that operates on streams.
sed 's/pattern/replace/' file > new
sed
does not change the contents of the original file.
Use >
to send changed output to a new file.
All lines: | sed ' command' filename |
One line: | sed ' line command' filename |
Range of lines: | sed ' startline,endline command' filename |
Commands:
s/
old/
new/
(with optional g
flag)
d
A line specification in sed
can be:
$
- the last line
/
pattern/
sed 's/hello/goodbye/g' new_file
sed '/foo/,/bar/d' file
sed '/bob/d' data
new_file
(but don't change new_file
!): sed '2,5d' new_file
foo
with bar
in the first 5 lines of file: sed '1,5s/foo/bar/g' file
sed 's/[,.?-]//g'
filename
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
diff
file1 file2
diff
describes the modifications that should be applied to
file1 to create file2
file1 | file2 |
hello world. |
hello world. |
% 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.
a
– add
c
– change
d
– delete
file
command 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
Modified: 2016-09-12T12:55 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |