Sei sulla pagina 1di 10

TYBCA SEM-5

Page 1

INDEX

Sr.
No.
Title
Page
No.
Sign.
1 APRIL-MAY 2006 2


2 OCTABER-NOVEMBER 2008 3


3 OCTABER-NOVEMBER 2010 4


4 NOVEMBER-DECEMBER 2006 5


5 SEPTEMBER-OCTOBER 2008 6


6 OCTOBER-NOVEMBER 2009 7


7 2007 8


8 MARCH- 2005 9




TYBCA SEM-5

Page 2

APRIL-MAY 2006
1) Replace the word UNIX with UNIX in between 5
th
to 10
th
lines including
both.
Sed 5,10s/UNIX/UNIX/ f1

2) Remove all leading spaces from a fle x1.
Sed s/^ *// x1

3) Display lines from fle x1 that contains at least 10 characters.
Sed n /.\ {10,/}\ x1

4) Assign value of 10
th
positonal parameter to a variable x.
x=$10

5) Display lines 10 to 15 from fle x1.
Sed 10,15p x1

6) Equivalent sed command of sed 1,5d x1.
Sed 1,5!p x1

7) Multply value of variable x with that of y and store the result in variable
x.
x=`expr $x+$y



TYBCA SEM-5

Page 3

Oct-Nov 2008
1) Display lines of fle f1 that do not contain any digit in it.
Grep e [!0-9]* f1

2) Replace all occurrences of linux OS with unix OS in fle f1.
Sed s/linux os/unix os/ f1

3) Create fle2 from fle1 such that it contains lines that begin with unix in
any case.
Grep e ^unix fle1 >fle2

4) Count those lines of fle that do not begin with alphabets.
Grep [0-9] f1 |wc l

5) Display name of all fles of working directory having patern the.
Cat * | grep the

6) Display lines of fle f1 and that begin with any capital leter.
Grep ^[A-Z] f1


TYBCA SEM-5

Page 4

Oct-Nov 2010
1) To cont number of words in lines 40 through 60 of fle f1.txt.
Echo word from line 40 through 60 is =cat fle.txt | head n 60 | tail n20
|wc w

2) To display those lines of fles f1 that contains exactly 50 characters in it.
Grep ^.\{50\}$ f1

3) To replace hello with HELLO in input fle fn.sh and write those lines to
output fle fout.sh.
Sed s/hello/HELLO/g fn.sh > fout.sh

4) Display all fles of working directory that contains hello patern in it.
More grep i hello *|cut d : f1|sort u

5) To display all lines that contains patern g* in a line.
Grep i g\* fle



TYBCA SEM-5

Page 5

Nov-Dec 2006
1) To replace the word Computer with Computng of fle x1.
Sed n s/computer/computng/pg x1

2) Display lines whose last word is UNIX of fle x1.
Grep unix$ x1

3) To return back user to his/her home directory without using home
directory name as an argument to that command.
Cd ~

4) Display lines of fle x1 that do not begins with caret(^).
Grep ve ^\^.* x1

5) Display only hidden fles of working directory.
la a|grep e ^\.

6) Display lines startng from 10
th
line to end of fle of fle x1.
Sed n 10,$p fle


TYBCA SEM-5

Page 6

Sep-Oct 2008
1) Select those lines that contain only digits.
Grep [0-9] f1

2) Display all line that start with let, from a fle x1. L, e or t may be in any
case.
Grep ^l[eE] [tT] x1.l

3) Count the frequency of each word in text fle.
wc w *.txt




TYBCA SEM-5

Page 7

Oct-Nov 2009
1) Write a UNIX command to evaluate the expression:4*3.14+6.
18.56

2) Write a command to display all lines that contains 2 or more ^ symbols at
beginning of lines.
Cat spe|grep ^\^\^.*

3) Write a command to replace all occurrences of he she and hello with
hi in fle f1.
Sed s/he/she/g s/hello/hi/g f1

4) Write a command to select lines having exactly 10 alphabets.
Cat he|grep i ^[a-z] [a-z] [a-z] [a-z] [a-z] [a-z] [a-z] [a-z] [a-z] [a-z]$

5) Write an equivalent IRE for the following regular expression:
sed s/he// is/g f1


TYBCA SEM-5

Page 8

2007
1) To replace all occurrences of words Zenix with Unix but only on those
lines where the word operatng found in fle INFILE.
Grep e operatng infle | sed s/zenix/unix

2) To display those lines between 20 and 50 having patern unix in it.
Sed 20,50p f1 | grep unix

3) To display those lines that contains two or more consecutve instances of
any word.
Sed n /[a-z] \ {3,\}/p f1

4) To display those lines of fle emp.dat in which third feld contains
director or chairman.
Cut d | f3 |grep e director e chairman

5) To locate lines that contains hardware, sofware or frmware.
Grep e hardware e sofware e frmware f1

6) To count all lines that end with digit.
Grep [$0-9] f1 |wc l




TYBCA SEM-5

Page 9

March 2005
1) To display last line of a fle x1.
sed $p x1

2) To display content of a fle named x1.dont use cat command.
sed p x1


Using awk
3) Only line having odd number of fles from fle x1.
$ awk '{if (NF%2==1)
print $0}
'f1

4) The length of the last feld of every line of fle x1.
$ awk '{ l=length($NF)
print 1}
'f1

5) Lines having at last three felds from fle x1.
$ awk '{if (NF>=3)
print $0 }
'f1

6) Fields of each line in reverse order of fle x1.
$ awk '{for (i=NF;i>=1;i--)
printf("%s\t",$i)
printf("\n")

TYBCA SEM-5

Page 10

Using grep
7) Count number of blank lines in fle x1.
grep "^\ \$p" abc.lst | wc

8) Display lines having at least one* character in fle x1.
grep \/*\p x1

9) Display lines from fle x1 that containing sring UNIX or unix Unix.
grep \[Uu][Nn][Ii][Xx]\p x1

Using sed
10) Three lines startng from 5
th
line of fle x1.
sed n 5,8p x1

11) All blank lines of fle x1.
sed ^\ \$p x1

12) Lines beginning either with alphabet or digit from fle x1.
sed -n '/^[0-9 a-z A-Z]/p' abc.lst