Laboratory Lecture 2
Laboratory Lecture 2
(CPET 529)
3. >> Operator
The operator >> appends to the file exists
or else creates it as a new file and writes
the data.
Syntax: cat sourcefile >> targetfile
Example:
Type gedit newfile1.txt and press enter.
Click save and open the terminal. Type the
command below
Reading Files in Linux [Cat, >, <,
>>]
Example 1:
[mcolivo@localhost Desktop]$ cat newfile.txt >>
newfile1.txt
Verify the output of newfile1.txt
Example 2:
[mcolivo@localhost Desktop]$ cat newfile1.txt >>
newfile.txt
Verify the output of newfile.txt
Linux Commands [Head, Tail, Sort]
Content of names.txt:
noddy
tom
jerry
donald
mickey
asterisk
tintin
obelix
Content of lines.txt:
Example 1:
[mcolivo@localhost Desktop]$ tail -3 name.txt
asterisk
tintin
obelix
Linux Commands [Head, Tail, Sort]
Example 2:
[mcolivo@localhost Desktop]$ tail -n4
name.txt
mickey
asterisk
tintin
obelix
Linux Commands [Head, Tail, Sort]
Example:
[mcolivo@localhost Desktop]$ wc -w
file1.txt
4 file1.txt
[mcolivo@localhost Desktop]$ wc -c file1.txt
21 file1.txt
[mcolivo@localhost Desktop]$ wc -l file1.txt
5 file1.txt
Linux Command
9. Grep Command
The grep command is one of the most powerful commands
in Linux. It matches the given pattern with each line of the
file and displays all lines that match the pattern.
Syntax: grep [character patterns] [filename].
Example 1:
Show the lines that has character pattern character lie
from the lines.txt and verify the output.
Example:
Show the print preview of lines.txt and
names.txt in 3 columns respectively.