Linux OS IMP Commands




1.Write a command to display all lines which begins with “NOKIA” string from an prd.lst file. [ prd.lst

grep
2.Delete first, last and all the blank lines from the specified file.
sed '/^$/d' das

5.Create a file named customer.dat which contains customer name, address and city.
a) Display all the lines who are started with A to M.
b) Display 5 lines after the match of the word “Bombay”.
1.grep ^[a-m] das
2.grep -A 5 surat das | tail -n 5

grep -A 5 surat das

6.Create columnar file named “emp” contains Empno, Empnm, Dept, Salary and Hiredate. Write
required command for following
a) Cut the Empnm and Salary column and transfer it to empsal file. Display the difference between
“emp” and “empsal” file and also display total number of words and characters of “emp” and
“empsal” file.
b) Sort the data in descending order of joining year and also transfer the sorted output in “experience”
file and display only unique lines of “experience” file.

a. cut -d "|" -f2 das | tee das1 echo 'diff das das1' && wc -wc das

b.sort -k1 -r dass -o dass1 |uniq -u dass1


7.Create columnar file named “emp” contains Empno, Empnm, deptno,Desig, and Salary. Write
required command for following
a. Cut the deptno,Empnm and Salary column and transfer it to empsal file. Also display first 4 and
7th onwards employees from empsal file.

a.
cut -d "|" -f 2 das > dasss |sed -n '5,6 !p' dasss


8.Create columnar file named “emp” contains Empno, Empnm, Desig, and Salary. Write required
command for following b) Cut the empno,empnm and transfer them into “empinfo.out” file and count
frequency of “SHAH” word of that file using single command.

O:cut -d "|" -f1,3 > dasss1 | grep parth das


9.Display all such files from your login which has size >= 50.

O:-find . -type f -size -5c (c means <=50)


10.Create columnar file named “restaurants” which contains restaurant name, pizza variety, delivery area
and prize columns
- Cut the restaurant name and price column and transfer it to file named “economy” and display first
3 three lines of the file “economy”.


O:- cut -d "|" f1,4 das > res | head -3 dasss



11.Display all the files with read and write permissions throughout your login and save output in file and
also display on terminal

O:- find -writable -readable | tee das



12.Write a command to substitute „/‟ with „:‟ throughout the file with all occurrences of /etc/group

O:- sed 's/,,\/"/,,:"/' das

13.Using awk command Count number of lines found in a file

o:- awk 'END {print NR}' das


14.Using awk command find Sum of fields ( Marks )
File Format roll#,name,mark1,mark2,mark3


O:-awk -F "|" '{print $3+$4}' das

15.Using awk command Remove duplicate lines ( similar to uniq) from file.


O:-awk -F "|" '{print}' dasss | sort |uniq

16.Using awk command Delete all Blank lines

O:- awk -F "|" '/./' dasss

17.Using awk command Print Last Line of a file
O:- awk -F "|" 'END{print}' dasss

18.Using awk command find and replace "Hindustan" or "Bharat" to "INDIA"

O:- awk -F "|" '{print}' dasss | sed -e 's/mca/das/' -e 's/bca'

19.Using awk command Print first line of a file
awk -F "|" 'NR==1{print}' dasss
sed -n '1p' dasss

20.Using awk command search for IND, BHA and HIN
awk -F "|" '/mca/||/bca/||/bov/ {print}' dasss

21.Using awk command search for IND and BHA and HIN (in that order)


22.Using awk command print only lines of less than 65 characters
O:-awk -F "|" 'length<65' dasss

23.Using awk command print section of file between two regular expressions (inclusive)
O:-awk -F "|" '(NR>=2 && NR<=8){print}' dasss


24.Using awk command print lines between 5 and 8 the line
O:-awk -F "|" '(NR>5 && NR<8){print}' dasss

Post a Comment

Previous Post Next Post