grep
grep regex textfile
grep -i regex FILE # look in FILE
cat FILE | grep -i word # look in the piped stream
fgrep
egrep
cat
cat FILE# print file to screen/stdout
cat FILE1 FILE2 # concatenates a set of files and prints to screen/stdout
Other less used options for cat
-n Precede each line output with its line number.
-b Number the lines, as -n, but omit the line numbers from blank lines.
-s cat is silent about non-existent files.
more and less
more displays the output of a command or text file one page at a time. The space bar is used to scroll down to the next page and q is used to quit. Examples :
more FILE
ls -l | more
less is similar to more but it has more options than more :
Searching :
/pattern: Search for pattern
n: Go to next match (after a successful search).
N: Go to previous match.
Navigation :
Space bar: Next page.
b: Previous page.
^ or g: Go to start of file.
‘$ or G: Go to end of file.
head and tail
The head command displays the first part of a file :
head FILE # Displays the first 10 lines of FILE.
head -20 FILE # Displays the first 20 lines of the file
head -n 20 FILE # Displays the first 20 lines - POSIX form
The tail command similarly displays the last part of a file :
tail FILE # Displays the last 10 lines of a file
tail -20 # Displays the last 20 lines of the file
tail -n 20 # Displays the last 20 lines - POSIX form
tail -f FILE # Displays new lines as they are written to FILE.
cut
cut is used to extract sections from each line of input (or of a file.)
echo "foo:bar:baz:qux:quux" | cut -d ":" -f 2 # separates each line into fields at the colon and returns the second field :
bar
echo "foo:bar:baz:qux:quux" | cut -d ":" -f 2- # gives the line from the second field to the end of line :
bar:baz:qux:quux
sort
The sort command sorts the lines of the input (or file) in alphabetical order.
uniq
removes duplicates from the output when used with uniq.
diff
compare two text files line by line
two filename arguments required
diff FILE1 FILE2 # single column comparison
diff -y FILE1 FILE2 # side by side comparison
diff -i FILE1 FILE2 # ignore case when comparing files
grep regex textfile
grep -i regex FILE # look in FILE
cat FILE | grep -i word # look in the piped stream
fgrep
egrep
cat
cat FILE# print file to screen/stdout
cat FILE1 FILE2 # concatenates a set of files and prints to screen/stdout
Other less used options for cat
-n Precede each line output with its line number.
-b Number the lines, as -n, but omit the line numbers from blank lines.
-s cat is silent about non-existent files.
more and less
more displays the output of a command or text file one page at a time. The space bar is used to scroll down to the next page and q is used to quit. Examples :
more FILE
ls -l | more
less is similar to more but it has more options than more :
Searching :
/pattern: Search for pattern
n: Go to next match (after a successful search).
N: Go to previous match.
Navigation :
Space bar: Next page.
b: Previous page.
^ or g: Go to start of file.
‘$ or G: Go to end of file.
head and tail
The head command displays the first part of a file :
head FILE # Displays the first 10 lines of FILE.
head -20 FILE # Displays the first 20 lines of the file
head -n 20 FILE # Displays the first 20 lines - POSIX form
The tail command similarly displays the last part of a file :
tail FILE # Displays the last 10 lines of a file
tail -20 # Displays the last 20 lines of the file
tail -n 20 # Displays the last 20 lines - POSIX form
tail -f FILE # Displays new lines as they are written to FILE.
cut
cut is used to extract sections from each line of input (or of a file.)
echo "foo:bar:baz:qux:quux" | cut -d ":" -f 2 # separates each line into fields at the colon and returns the second field :
bar
echo "foo:bar:baz:qux:quux" | cut -d ":" -f 2- # gives the line from the second field to the end of line :
bar:baz:qux:quux
sort
The sort command sorts the lines of the input (or file) in alphabetical order.
uniq
removes duplicates from the output when used with uniq.
diff
compare two text files line by line
two filename arguments required
diff FILE1 FILE2 # single column comparison
diff -y FILE1 FILE2 # side by side comparison
diff -i FILE1 FILE2 # ignore case when comparing files
No comments:
Post a Comment