Tutorial 4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

University Poly Tech Malaysia

Faculty of Computing and Multimedia

ARC2163 Tutorials 4
UNIX Filters

Task 1: Using head and tail


Try the following commands and explain the outputs:

ls –l | head -5

ls –l | tail -3

Task 2: Using tr
Try the following commands and explain the outputs:

ls –l | tr ‘a-z’ ‘A-Z’

ls –l | tr ‘ ‘ ‘\n’ | more

Task 3: Using sort


Try the following commands and explain the outputs:

ls –l | sort +1 -2

ls –l | sort +4

ls –l | sort +2.3 -3.7

Task 4: Using grep


Try the following commands and explain the outputs:

ls –l | grep pattern

Task 5: Using sed


Try the following commands and explain the outputs:

ls –l | sed ‘1,3p’

ls –l | sed –n ‘1,3p’

ls –l | sed –n ‘1,3d’

ls –l | sed ‘s/filename/newfile/’ (filename is the name of one of files in the dir)


Task 6: Create a text file consisting of at least ten lines.

Write commands for

(i) Printing the first two lines of the file

(ii) Listing all of the words in the file in a single column

(iii) Sorting these words in ascending order

(iv) Removing duplicate words, so print only list of unique words

You might also like