+ All Categories
Home > Documents > FOSS Lab --V Prasad,2013

FOSS Lab --V Prasad,2013

Date post: 12-Apr-2018
Category:
Upload: prasad9440024661
View: 226 times
Download: 1 times
Share this document with a friend

of 51

Transcript
  • 7/21/2019 FOSS Lab --V Prasad,2013

    1/51

    1

    FREE OPEN SOURCE SOFTWARE(FOSS) Lab

    Manual.

    R13 Syllabus JNTUK

    Faculy

    P!"#a!"$ by % P!asa$&

    Ass'ca" P!'"ss'! & *"# ' CSE.

    .

    Ra+,u -nsu" ' T"c,n'l'+yA##!'"$ by A-CTE(N"/ *"l,) & Ala"$ ' JNTU0K(Kana$a & An$,!a P!a$"s,)&

    *aa2a!!(%)& ,""2un#ana2 (M)& %sa,a#ana2 *s!c& An$,!a P!a$"s,& -n$a.

    T"l N'4 561 7688 897::3& 897:13. Fa; n'4 561 7688 897:13. W"bs"4 ///.!a+,uns"c,.c'2

    Raghu Institute of Technology II Year

    II Sem Computers

  • 7/21/2019 FOSS Lab --V Prasad,2013

    2/51

    2

    LA OJECT-%E

    This is the BASIC Language at engineering level which gives a foundation for

    the upcoming period.

    Logical thinking is given for solving the given problem.

    The learned c language can help a student at industry level.

    ives enough knowledge in C basics.

    !ore idea on Algorithms " #lowcharts.

    $sage of Algorithms " #lowcharts.

    %ifference between process and program can understood.

    %ifference between Algorithm and &seudocode .

    Several programs in C for perfection in syntactic " semantic representation.

    'orking ability can be increases on (I )ditor and )!ACS editor in #)%*+A ,

    S$S) linu-. (arious header file usages and the methodologies used for compiling them is

    known umber Systems like BC% / *ctal / 0e-adecimal can be viewed.

    Clear deviations in !achine Language / Assembly Language / Application

    languages is done. Interesting topics like Arrays / &ointers / #unctions/ Structures " $nions can be

    implemented. %iscussion a variety of current issues related to using C in educational settings.

    %iscussion on advantages and disadvantages in C .

    $sed Inbuilt (I )ditor from #)%*+A, S$SI Linu- and e-ecuted all programson it.

    Came to know how secure the LI$1 operating system is.

    Came to know the difference between programs and files.

    2nown the difference between compile time e-ecution and run time e-ecution.

    Completion of my lab taught me saying that C is an *cean and there is lot more

    to work on.3 like graphics / multimedia / dynamic data collection 45

    RA"a! ? P!'+!a22" 4 -- >"a!& 8:13019

    Raghu Institute of Technology II Year

    II Sem Computers

  • 7/21/2019 FOSS Lab --V Prasad,2013

    3/51

    3

    !anc, @ S"2"s"! 4 CSE @ -- S"2"s"!

    E;#"!2"n1

    S"ss'n01

    a5Log into the systemOu#u 4 Login

    b5$se vi editor to create a file called myfile.t-t which contains some te-t.Ou#u 4 vi mytable

    c5correct typing errors during creation.Ou#u 4 &ractice vi editor commands6

    d5Save the fileOu#u 4 7w8 9)nter

    e5logout of the systemOu#u 4 logout

    To Enter VI Editor:

    T' Sa!

    To use vi on a file/ type in vi filename. If the file named filename e-ists/ then thefirst page 3or screen5 of the file will be displayed: if the file does not e-ist/ then

    an empty file and screen are created into which you may enter te-t.

    vi filename edit filename starting at line 1

    vi ;r filename recover filename that was being edited when systemcrashed

    T' E;

    $sually the new or modified file is saved when you leave vi. 0owever/ it is alsopossible to 8uit vi without saving the file.

    N'"4 The cursor moves to bottom of screen whenever a colon 375 is typed. This type of command is completed by hitting the

  • 7/21/2019 FOSS Lab --V Prasad,2013

    4/51

    4

    7- quit vi, writing out modified file to file named in original invocation

    7w8 quit vi, writing out modified file to file named in original invocation

    78 quit (or exit) vi

    78> quit vi even though latest changes have not been saved for this vi call

    S"ss'n08

    a5Log into the system

    b5open the file created in session ?c5Add some te-t

    d5Change some te-te5%elete some te-tf5Save the ChangesOu#u 4 &ractice the commands in (i editor g5Logout of the system

    N'" Ma" Us" ' 'll'/n+ c'22an$s

    -ns"!n+ '! A$$n+ T";

    The following commands allow you to insert and add te-t. )ach of these commandsputs the vi editor into insert mode: thus/ the

  • 7/21/2019 FOSS Lab --V Prasad,2013

    5/51

    5

    cc change (replace) the entire current line, stopping when is hit

    change (replace) the next lines, starting with the currentline, NccorcNcstopping when is hit

    *"l"n+ T";

    The following commands allow you to delete te-t.

    B ;

    N;

    $/

    $N/

    delete single character under cursor

    delete characters, starting with character under cursor delete the

    single word beginning with character under cursor

    delete words beginning with character under cursor! e"g", d#wdeletes # words

    * delete the remainder of the line, starting with current cursor position

    B$$ delete entire current line

    N$$ or$N$ delete lines, beginning with the current line!

    e"g", #dd deletes # lines

    Raghu Institute of Technology II Year

    II Sem Computers

  • 7/21/2019 FOSS Lab --V Prasad,2013

    6/51

    E;#"!2"n8

    a5Log into the system

    b5$se the cat command to create a file containing the following data. Call it mytableuse tabs to separate the fields.

    ? +avi ?.DEF +amu D.GDHEF Sita ED.??F +au ?.HD

    Ou#u

    cat = mytable? +avi ?.DEF +amu D.GDHEF Sita ED.?

    ?F +au ?.HD

    c5$se the cat command to display the file/mytable.Ou#u 4 Jcat mytable

    ?BC +avi ?.DEBF +amu D.GDHEF Sita ED.??CF +au ?.HD

    d) $se the vi command to correct any errors in the file mytable./Ou#u 4 (erify the file with (i editor Commands

    e) $se the sort command to sort the file mytable according to the first field. Callthe sorted file my table3 same name5Ou#u 4 Jsort 9? mytable = mytable

    f) &rint the file mytableOu#u 4 cat mytable? +avi ?.D?F +au ?.HDEF +amu D.G

    DHEF Sita ED.?

    g5 $se the cut and paste commands to swap fields and E of mytable. Call it mytable 3same name5

    Ou#u 4 Jcut Kf? =mytab? J cut ;f =mytab Jcut ;f E =my tabE

  • 7/21/2019 FOSS Lab --V Prasad,2013

    7/51

    Jpaste mytabE mytab =mytab Jpaste mytab?mytab = mytable

    h5&rint the new file/ mytableOu#u 4 J cat mytable?BC ?.D +avi?CF ?.HD +auEBF D.G +amuDHEF ED.? Sita

    i5Logout of the system.

    Ca40000

    ca to display a text file or to concatenate files

    ca l"1displays contents of file? on the screen 3or window5without any screen breaks.

    ca l"1 l"8

    displays contents of file? followed by file on the

    screen 3or window5 without any screen breaks.

    ca )(l"1 )(l"8 C )(l"3 creates fileE containing file? followed by file

    S'! 40000

    The sort command sorts information piped into it. There are several options that

    let you sort information in a variety of ways.#s 0" D s'!

    T," 2's 2#'!an '#'ns n S'! 4

    The following list describes the options and their arguments that may be used tocontrol how s'!functions.

    #orcess'! to read from the standard input.$seful for reading frompipes andfiles simultaneously"

    0c (erifies that the input is sorted according to the other optionsspecified on thecommand line. If the input is sorted correctly then

    no output is provided. If the input is not sorted then s'! informsyou of the situation. The message resembles this. sort7 disorder7 This line not in sorted order. Km !erges the sorted input. s'! assumes the input is already

    sorted. s'!normally merges input as it sorts. This option informss'!that the input is already sorted/ thus s'!runs much faster.

    0' output Sends the output to file output instead of the standardoutput. Theoutputfile may be the same name as one of the inputfiles.

    0u Suppress all but one occurrence of matching keys. ormally/ the

  • 7/21/2019 FOSS Lab --V Prasad,2013

    8/51

    entire line is the key. If field or character keys are specified/ thenthe suppressing is done based on the keys.

    0y kmem$se%memkilobytes of main memory to initially start thesorting. If more memory is needed/ s'! automatically re8uests itfrom the operating system.

    0 recs&Specifies the record siMe used to store each line. ormally the

    recs&is setto the longest line read during the sort phase. If the Kc orKm options are specified/ the sort phase is not performed and thus therecord siMe defaults to a system siMe.

    The amount of memory allocated for the sort impacts the speed of the sortsignificantly. If no kmem is specified, sort starts with the default amount ofmemory (usually 32K) The ma-imum 3usually ? !egabyte5 amount of memorymay be allocated if needed.

    If F is specified for %mem/ the minimum 3usually ?D25 amount of memory isallocated.

  • 7/21/2019 FOSS Lab --V Prasad,2013

    9/51

    If this default siMe is not large enough/ s'!may abort during the merge phase. Toalleviate this problem you can specify a recs&that will allow the merge phase to runwithout aborting. E;#"!2"n3

    S"ss'n14

    a5Login to the system

    b5$se the appropriate command to determine your login shell

    Ou#u 4 Jecho JS0)LLsh

    c5$se the ,etc,passwd file to verify the result of step b.

    Ou#u 4 Jcat ,etc,passwd

    d5$se the who command and redirect the result to a file called myfile?. $se themore command to see the contents of myfile?.

    Ou#u 4 Jwho = myfile? N more

    $ser? pts,F Apr E ?F7E

    $ser pts,? !ay D ?H7?O

    e5$se the date and who commands in se8uence 3in one line5 such that the outputof date will display on the screen and the output of who will be redirected to afile called myfile. $se the more command to check the contents of myfile.

    Ou#u 4 J date : who = myfile

    #ri April O ?D7G7E IST F?E Cat myfile 7

    $serE pts, Apr ?F7E

    $ser pts,E !ay H ?H7?OW,' 4000

    The who command lets you display the users that are currently logged intoyour $ni- computer system.

    /,'

    This is the basic who command with no commandKline arguments. It shows the names ofusers that are currently logged in/ and may also show the terminal theyPre logged in on/and the time they logged in.

  • 7/21/2019 FOSS Lab --V Prasad,2013

    10/51

    /,' D 2'!"

    In this e-ample the output of the who command is piped into the more command. Thisis useful when there are a lot of users logged into your computer system/ and part of theoutput of the who command scrolls off the screen. See the more command for moree-amples.

    /,' 0a

    The Ka argument lists all available output of the who command for each user.

    &iping7KKK

    To connect the output of the one command directly to the input of the other command.

    This is e-actly what pipes do. The symbol for a pipe is the vertical bar N

    #or e-ample/ typing

    /,' D s'!

    will give the same result as above/ but 8uicker and cleaner.

    To find out how many users are logged on/ type

    http://www.devdaily.com/unix/edu/examples/more.shtmlhttp://www.devdaily.com/unix/edu/examples/more.shtml
  • 7/21/2019 FOSS Lab --V Prasad,2013

    11/51

    /,' D /c 0lSession 7

    -n#u Fl" 4 l"1.$a 4

    Un; s Mulus"! OS

    Un; /as $""l'#"$ by !an K"!n+,an an$ K"nT,'2s'n

    a5'rite a sed command that deletes the first character in each line in a file.

    Ou#u4s"$Ps,Q., ,file?.datn; s Mulus"! OS

    n; /as $""l'#"$ by !an K"!n+,an an$ K"nT,'2s'n

    b5'rite a sed command that deletes the last character in each line in a file.

    Ou#u4

    sed PJs,.J,,P file?.datUn; s Mulus"! O

    Un; /as $""l'#"$ by !an K"!n+,an an$ K"nT,'2s'

    c5'rite a sed command that swaps the first and second words in each line in afile.

    Ou#u4sed Ke Ps,63RQ 6965 @63RQ 6965,6 6?,P

    sed Ps,63RaKM@65 63RaKM@65,6 6?,P 3!odified " working5

    3Substrings enclosed with 63 and 65 can be referenced with 6n 3n is a digit from ?to O5 5

    +ef 7 http7,,www.grymoire.com,$ni-,Sed.htmluhKF

    http://www.grymoire.com/Unix/Sed.html#uh-0http://www.grymoire.com/Unix/Sed.html#uh-0
  • 7/21/2019 FOSS Lab --V Prasad,2013

    12/51

    E;#"!2"n9

    a5&ipe your ,etc,passwd file to awk/ and print out the home directory of each user.

    Ou#u4cat ,etc,passwd N awk U V print JGW

    b5%evelop an interactive grep script that asks for a word and a file name and then tellshow many lines contain that word.

    Ou#u4

    echo X)nter a wordYread word

    echo X)nter the filenameYread filenolZgrep Kc Jword Jfile

    echo X Jnol times Jword present in the JfileY

    c5&art using awk

    Ou#u4

    echo X)nter a wordYread word

    echo X)nter the filenameYread filenolZawk U,Jword, V print + W Infileecho X Jnol times Jword present in the JfileY

    specifiedwords or patterns. #irst clear the screen/ then type

    +!"# sc"nc" sc"nc".;

    As you can see/ +!"#has printed out each line containg the word sc"nc".*r has it [[[[Try typing +!"# Sc"nc" sc"nc".;

    The +!"#command is case sensitive: it distinguishes between Science and science.

    To ignore upper,lower case distinctions/ use the Ki option/ i.e. type

  • 7/21/2019 FOSS Lab --V Prasad,2013

    13/51

    +!"# 0 sc"nc" sc"nc".;

    To search for a phrase or pattern/ you must enclose it in single 8uotes 3the

    apostrophe symbol5. #or e-ample to search for spinning top/ type

    +!"# 0 Gs#nnn+ '#G sc"nc".;

    Some of the other options of grep are7

    0 display those lines that do *T match

    0nprecede each matching line with the line

    number0cprint only the total count of matched

    lines

    Try some of them and see the different results. %onPt forget/ you can use more than

    one option at a time. #or e-ample/ the number of lines without the words scienceor Science is

    +!"# 0c sc"nc" sc"nc".;

    +ef 7 http7,,www.grymoire.com,$ni-,Awk.html

    http://www.grymoire.com/Unix/Awk.htmlhttp://www.grymoire.com/Unix/Awk.html
  • 7/21/2019 FOSS Lab --V Prasad,2013

    14/51

    E;#"!2"nH

    a5'rite a shell script that takes a command ;line argument and reports on whether it isdirectory/ a file/ or something else.

    Ou#u4echo enterfile read strif test Kf Jstr

    then echo file e-ists n it is an ordinaryfile elif test Kd Jstr

    then echo directoryfile else

    echo note-ists fiif test Kc Jstr

    then echo character device

    files fi

    b5'rite a shell script that accepts one or more file name as arguments and converts all ofthem to uppercase/ provided they e-ist in the current directory.

    Ou#u4

    ' get filename

    echo Kn )nter #ile ame 7 read fileame

    # ma%e sure file exits for reading

    if R > Kf Jfileame then

    echo #ilename Jfileame does note-ists e-it ?fi

    # convert uppercase to lowercase using trcommand tr PRAK\P PRaKMP < Jfileame

    c5'rite a shell script that determines the period for which a specified user is working onthe system.

    Ou#u4

    echo Xenter the login of theuserY read name

    logindetailsZ]whoNgrep ;w XJnameY N grepXttyY if R J[ ;ne F then

    echo XJname has not logged in

  • 7/21/2019 FOSS Lab --V Prasad,2013

    15/51

    yetY e-itfiloginhoursZ]echo XJlogindetailsY N cut ;c D/G]loginminutsZ]echo XJlogindetailsY N cut ;c OKEF]hoursnowZdate N cut ;c ?/?E]

    minnow Z]date N cut ;c ?/?D]hourZ]e-pr Jloginhours K Jhoursnow]minZ]e-pr Jloginminuts K Jminnow]echo X Jname is working sinceJhour 0rs K Jmin !inutsY

  • 7/21/2019 FOSS Lab --V Prasad,2013

    16/51

    E;#"!2"nI

    a5'rite a shell script that accepts a file name starting and ending line numbers asarguments and displays all the lines between the given line numbers.

    Ou#u4

    If R J Kne E then

    echo Xchech the arguments onceYlastlineZwc ;l < J?

    if R J ;lt Jlastline ;a JE Kle Jlastline thennlineZe-pr JE KJ 9 ?

    echo Xtail 9J J? N head KJnlineY else

    echo Xinvalid range specificationYfifi

    b5 'rite a shell script that deletes all lines containing a specified word in one or morefiles supplied as arguments to it.

    Ou#u4if R J Klt ?then

    echo X Chech the arguments onceYe-itfi

    echo X)nter awordY read word

    for file inJ@ do

    grep ;iv XJwordY Jfile N tee ?= ,dev,nulldoneecho X lines containing given word are deletedY

  • 7/21/2019 FOSS Lab --V Prasad,2013

    17/51

    E;#"!2"n

    a5'rite a shell script that computes the gross salary of a employee according to thefollowing rules7

    i5If basic salary is < ?FF then 0+A Z?F^ of the basic and %A ZOF^ of the basic.ii5If basic salary is =Z?FF then 0+A Z+sFF and %AZOH^ of the basic

    The basic salary is entered interactively through the key board.

    Ou#u4

    echo enter basic salaryread salaZF.?

    bZF.Hecho Jaecho hra is

    hraZ]echo F.? 6@ JsalNbc] echo da is

    daZ]echo F.H6@JsalNbc]gsalZe-pr Jhra 9 Jda 9Jsalecho Jgsal

    b5'rite a shell script that accepts two integers as its arguments and computers the valueof first number raised to the power of the second number.

    Ou#u4

    If R J Kne then

    echo Xchech the number of argumentsYcountZ?resultZ?

    if R J ;ge F then

    while R Jcount ;le J do

    resultZ]e-pr Jresult 6@ J?]countZ]e-pr Jcount 9 ?]done

    fi

  • 7/21/2019 FOSS Lab --V Prasad,2013

    18/51

    fiE;#"!2"n7

    a5'rite an interactive fileKhandling shell program. Let it offer the user the choice ofcopying/ removing/ renaming/ or linking files. *nce the user has made a choice/ have theprogram ask the user for the necessary information/ such as the file name/ new name andso on.

    b5'rite shell script that takes a login name as command ; line argument and reportswhen that person logs in

    Ou#u4

    Shell script that takes loginname as command line arg and reports when that person logsin.

    if R J Klt ? thenecho improper usage

    echo correct usage is7 JF usernamee-it

    filognameZJ? while truedo

    whoNgrep Jlogname=,dev,nullif R J[ Z F then

    echo Jlogname has logged inecho Jlogname==shF?log.t-tdate ==shF?log.t-techo 0i = mesg.t-t

    echo Jlogname == mesg.t-techo 0ave a ood %ay ==mesg.t-t mail Jlogname < mesg.t-t

    e-itelsesleep DF fi done

    c5'rite a shell script which receives two file names as arguments. It should checkwhether the two file contents are same or not. If they are same then second file shouldbe deleted.

    S'l4

    echo Xenter first file nameYread file?echo X enter second file nameYread filecmp file? file = fileE

    if R KM Jfile? rm file

  • 7/21/2019 FOSS Lab --V Prasad,2013

    19/51

    fiecho Xduplicate file deleted successfullyY

  • 7/21/2019 FOSS Lab --V Prasad,2013

    20/51

    E;#"!2"n6

    a5'rite a shell script that displays a list of all the files in the current directory to whichthe user has read/ write and e-ecute permissions.

    Ou#u4

    ls ;l N grep XQ.rw-Y N cut ;f O

    b5%evelop an interactive script that ask for a word and a file name and then tells howmany times that word occurred in the file.

    c5'rite a shell script to perform the following string operations7i5To e-tract a subKstring from a given string.ii5To find the length of a given string.

    ote7 !ake use of #ollowing Link to know about Shell &rogramming

    +ef 7 http7,,www.freeos.com,guides,lsst,chF.html

    http://www.freeos.com/guides/lsst/ch02.htmlhttp://www.freeos.com/guides/lsst/ch02.html
  • 7/21/2019 FOSS Lab --V Prasad,2013

    21/51

    E;#"!2"n1:

    'rite a C program that takes one or more file or directory names as command line input andreports the following information on the file7i5#ile typeii5umber of links

    iii5+ead/ write and e-ecute permissionsiv5Time of last access

    Ou#u4

    include

  • 7/21/2019 FOSS Lab --V Prasad,2013

    22/51

    int stat3const char @restrictpath/ struct stat @restrict buf5:

    *ESCR-PT-ON

    Thestat35 function shall obtain information about the named file and write it to the areapointed to by the bufargument. Thepathargument points to a pathname naming a file. +ead/write/ or e-ecute permission of the named file is not re8uired. An implementation thatprovides additional or alternate file access control mechanisms may/ under implementationKdefined conditions/ causestat35 to fail. In particular/ the system may deny the e-istence of thefile specified bypath.

    If the named file is a symbolic link/ the stat35 function shall continue pathnameresolution using the contents of the symbolic link/ and shall return information pertainingto the resulting file if the file e-ists.

    The bufargument is a pointer to a sastructure/ as defined in the 7KKK

    The sastructure shall contain at least the following members7

    dev_t st_dev %evice I% of device containing file.ino_t st_ino #ile serial number.mode_t st_mode !ode of file 3see below5.

    nlink_t st_nlink umber of hard links to the file.uid_t st_uid $ser I% of file.gid_t st_gid roup I% of file.dev_t st_rdev %evice I% 3if file is character or block special5.off_t st_siMe #or regular files/ the file siMe in bytes.

    #or symbolic links/ the length in bytes of the pathname contained in the symbolic link.

    http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.htmlhttp://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_07http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.htmlhttp://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.htmlhttp://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_07http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html
  • 7/21/2019 FOSS Lab --V Prasad,2013

    23/51

    #or a shared memory obect/ the length in bytes.

    #or a typed memory obect/ the length in bytes.

    #or other file types/ the use of this field is unspecified.time_t st_atime Time of last access.time_t st_mtime Time of last data modification.time_t st_ctime Time of last status change.blksiMe_t st_blksiMe A file systemKspecific preferred I,* block

    siMe for this obect. In some file system types/ this may vary fromfile to file.

    umber of blocks allocated for this obect.

  • 7/21/2019 FOSS Lab --V Prasad,2013

    24/51

    E;#"!2"n11

    'rite C programs that simulate the following uni- commands7a5mvOu#u4

    include

  • 7/21/2019 FOSS Lab --V Prasad,2013

    25/51

    W

    Sys"2 calls '! Fl" P!'c"ssn+ 7KKKK

    #reeBS% 3.5 has si- fileKrelated system calls. The following table briefly describe thefunction of each.

    Sys"2 calls Func'n

    open open an e-isting file or create a new file

    read +ead data from a file

    write 'rite data to a file

    lsee% !ove the read,write pointer to the specified location

    close Close an open file

    unlin% %elete a file

    chmod Change the file protection attributes

    stat +ead file information from inodes

    #iles to be included for fileKrelated system calls.

    'include

    'include

    'include

  • 7/21/2019 FOSS Lab --V Prasad,2013

    26/51

    Fla+ *"sc!#'n

    +-+./ open for reading only

    +0+./ open for writing only

    +-0 open for reading and writing++.+23 do not block on open

    +455E- append on each write

    +2E46 create file if it does not e-ist

    +6$2 truncate siMe to F

    +E72. error if create and file e-ists

    +89.+23 atomically obtain a shared lock

    +E7.+23 atomically obtain an e-clusive lock

    +-:E26 eliminate or reduce cache effects

    +;8/2 synchronous writes

    ++;+..+0 do not follow symlinks

    The flag 3+2E465 may be used to create the file if it does not e-ist. 'hen this flag isused/ the third parameter 3modes5 must be used to specify the file access permissionsfor the new file. Commonly used modes 3or access permissions5 include

    C'nsan Na2"

    Ocal

    %alu"

    S_I+'1$ FFFFGFF

    S_I+$S+ FFFFFF

    S_I'$S+ FFFFBFFS_I1$S+ FFFF?FF

    S_I+'1* FFFFFFG

    S_I+*T0 FFFFFFS_I'*T0 FFFFFFBS_I1*T0 FFFFFF?

    read, 0 write, and 7executable

    *"sc!#'n

    ,@ +'1 mask for owner @,

    ,@ + for owner @, ,@ 'for owner @, ,@ 1 forowner @,

    ,@ +'1 mask for other @,

    ,@ + for other @, ,@ 'for other @, ,@ 1 forother @,

  • 7/21/2019 FOSS Lab --V Prasad,2013

    27/51

    #or e-ample/ to open file tmp.t-t in the current working directory for readingand writing7

    fd = open(tmp"txt, +-0)!

    To open sample.t-t in the current working directory for appending or create it/ if itdoes not e-ist/ with read/ write and e-ecute permissions for owner only7

    fd = open(tmp"txt, +0+./?+455E-?+2E46, 8:07$)!

    A file may be opened or created outside the current working directory. In this case/ anabsolute path and relative path may prefi- the file name. #or e-ample/ to create a filein ,tmp directory7

    open(tmptmp"txt, +-0)!

    R"a$ !'2 l"s

    The system call for reading from a file is read. Its synta- is

    ssi&et read(int fd, void *buf, si&et nbytes)!

    The first parameter fd is the file descriptor of the file you want to read from/ it isnormally returned from open. The second parameter buf is a pointer pointing thememory location where the input data should be stored. The last parameter nbytesspecifies the ma-imum number of bytes you want to read. The system call returns thenumber of bytes it actually read/ and normally this number is either smaller or e8ual to

    nbytes. The following segment of code reads up to ?F bytes from file tmp.t-t7

    int actual_count Z F:

    int fd Z open3tmp.t-t/ *_+%*L`5:void @buf Z 3char@5 malloc3?F5:

    actual_count Z read3fd/ buf/ ?F5:

    )ach file has a pointer/ normally called read,write offset/ indicating where ne-t readwillstart from. This pointer is incremented by the number of bytes actually read by the readcall. #or the above e-ample/ if the offset was Mero before the readand it actually read?F bytes/ the offset will be ?F when the readreturns. This offset may be changed bythe system call lsee%/ which will be covered shortly.

    W!" ' l"s

    The system call writeis to write data to a file. Its synta- is

    ssi&et write(int fd, const void *buf, si&et nbytes)!

  • 7/21/2019 FOSS Lab --V Prasad,2013

    28/51

    It writes nbytesof data to the file referenced by file descriptorfdfrom the buffer pointedby buf. The writestarts at the position pointed by the offset of the file. $pon returningfrom write/ the offset is advanced by the number of bytes which were successfullywritten. The function returns the number of bytes that were actually written/ or it returnsthe value K? if failed.

  • 7/21/2019 FOSS Lab --V Prasad,2013

    29/51

    E;#"!2"n18

    'rite a C program that simulates ls Command

    Ou#u4

    include

  • 7/21/2019 FOSS Lab --V Prasad,2013

    30/51

    +ef 7 http7,,www.opengroup.org,onlinepubs,FFODOEOO,functions,opendir.html

    !"a$$!()4000

    NAME

    readdir/ readdir_r K read a directory

    S>NOPS-S

    include

  • 7/21/2019 FOSS Lab --V Prasad,2013

    31/51

    The readdir35 function may buffer several directory entries per actual read operation:readdir35 shall mark for update the statime field of the directory each time thedirectory is actually read.

    After a call to for%35/ either the parent or child 3but not both5 may continueprocessing the directory stream using readdir35/ rewinddir35/or see%dir35.If both theparent and child processes use these functions/ the result is undefined.

    If the entry names a symbolic link/ the value of the dinomember is unspecified.

    The readdir35 function need not be reentrant. A function that is not re8uired to bereentrant is not re8uired to be threadKsafe.

    The readdirr35 function shall initialiMe the $!"nstructure referenced by entry torepresent the directory entry at the current position in the directory stream referred toby dirp/ store a pointer to this structure at the location referenced by result/ andposition the directory stream at the ne-t entry.

    The storage pointed to by entryshall be large enough for a $!"nwith an array ofc,a! dnamemembers containing at least VA!)_!A1W9? elements.

    $pon successful return/ the pointer returned at @resultshall have the same value as theargument entry. $pon reaching the end of the directory stream/ this pointer shall havethe value $LL.

    The readdirr35 function shall not return directory entries containing empty names.

    If a file is removed from or added to the directory after the most recent call toopendir35or rewinddir35/whether a subse8uent call toreaddirr35 returns an entryfor that file is unspecified.

    The readdirr35 function may buffer several directory entries per actual readoperation: the readdirr35 function shall mark for update thestatimefield of thedirectory each time the directory is actually read.

    Applications wishing to check for error situations should set errnoto F before callingreaddir35. Iferrno is set to nonKMero on return/ an error occurred.

    RETURN %ALUE

    $pon successful completion/ readdir35 shall return a pointer to an obect of type s!uc$!"n. 'hen an error is encountered/ a null pointer shall be returned and errno shallbe set to indicate the error. 'hen the end of the directory is encountered/a null pointershall be returned and errnois not changed.

    If successful/ the readdirr35 function shall return Mero: otherwise/ an error numbershall be returned to indicate the error.

    http://www.opengroup.org/onlinepubs/009695399/functions/fork.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/fork.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/seekdir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/seekdir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/opendir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/opendir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/fork.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/seekdir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/opendir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/opendir.htmlhttp://www.opengroup.org/onlinepubs/009695399/functions/rewinddir.html
  • 7/21/2019 FOSS Lab --V Prasad,2013

    32/51

  • 7/21/2019 FOSS Lab --V Prasad,2013

    33/51

    ?.W!" a n'n !"cu!s" s,"ll sc!# /,c, acc"#s any nu2b"! ' a!+u2"ns an$#!ns ,"2 n ," !""!s" '!$"! ('! ";a2#l"& ," sc!# s na2"$ !a+s& ,"n

    ";"cun+ !a+s AC s,'ul$ #!'$uc" CA 'n ," san$a!$ 'u#u

    P!'+!a2 4

    aZJecho umber of arguments are Ja-ZJ@cZJaresZPPwhile R ? Kle Jc docZ]e-pr Jc K ?]shift JcresZJresP PJ?set J-

    doneecho Arguments in reverse order Jres

    Ou#u

    sh ?prg.sh a b co of arguments arguments are EArguments in reverse order c b a

    . W!" a s,"ll sc!# ,a acc"#s /' l" na2"s as a!+u2"ns& c,"cs ,"#"!2ss'ns '! ,"s" l"s a!" $"ncal an$ ," #"!2ss'ns a!" $"ncal&

    'u#u c'22'n #"!2ss'ns an$ ',"!/s" 'u#u "ac, l" na2" 'll'/"$ by s

    #"!2ss'ns.

    P!'+!a2 4

    if R J Kne thenecho pass argumente-itfiecho enter file nameread f?echo enter the second file nameread fp?Z]ls Kl Jf? N cut Kc K?F]pZ]ls Kl Jf N cut Kc K?F]if R Jp? Z Jp thenecho permissions are sameecho Jp?

  • 7/21/2019 FOSS Lab --V Prasad,2013

    34/51

    elseecho permissions are differentecho permission of file Jf? is Jp?echo permission of file Jf is Jpfi

    Ou#u4

    enter file name?Fa.shenter the second file namea.shpermissions are samerwKrKKrenter file name?enter the second file name

    ?Fa.shpermissions are differentpermission of file ? is rw-rw-rw-permission of file is rwKrKKr

    E.W!" a s,"ll sc!# ,a a"s a al$ $!"c'!y na2" as an a!+u2"n an$!"cu!s"ly $"sc"n$ all ," sub$!"c'!"s& n$s ," 2a;2u2 alu" ' ,"

    san$a!$ 'u#u.

    P!'+!a24

    clearif R J Kne ? thenecho ;e X6n6nInvalid umber of arguments passed6nYe-itficd J?echo The directory name is J?set KK ] ls Kl+N grep Kv Qd Nsort 9 K Krn]echo siMe of the largest file is J blocks

    Ou#u

    sh a.sh rvThe directory name is rvsiMe of the largest file is ?E? blocks

    .A2 ' acc"#s a #a, na2" an$ c!"a"s all ," c'2#'n"ns n ,a #a,na2" as $!"c'!"s.

    P!'+!a24

  • 7/21/2019 FOSS Lab --V Prasad,2013

    35/51

    tempZI#SI#SZ,iZJfor i in J@

    doif R Kf Ji thene-itfiif R Kd Ji thencd Jielsemkdir Jiecho Ji is in ]pwd]

    cd JifidoneIfSZJtemp

    Ou#u

    sccselinu-7J sh b.sh d? d dEd? is in home scd is in home sc d?dE is in home sc d? d

    .A2 ' s,'/ ," #!nn+ ' ,"! c'!!"s#'n$n+ ,'2" $!"c'!"s by acc"#n+al$ l'+0n na2"s as a!+u2"ns.

    P!'+!a24

    for nam in J@doyZ]grep Jnam ,etc,passwd N cut Kd 7 Kf?]if R Kn Jy thenif R Jy Z Jnam then-Z] grep Jnam ,etc,passwd N cut Kd 7 KfD]echo home directory of Jnam is J-elseecho Jnam doesnPt have an account fifidone

  • 7/21/2019 FOSS Lab --V Prasad,2013

    36/51

    Ou#u 4

    sh Ea.sh cse?F?home directory of cse?F? is ,home,cse?F?

    sh Ea.sh csecse does not have an account

    D.A2 ' 2#l"2"n "!2nal l'cn+ (s2la! ' ," l'c c'22an$). N' 2"l2 n""$ b" 2#l"2"n"$ '! ," l'c $u!a'n.

    P!'+!a2

    clearstty Kechoecho enter password to lock the terminal

    read pass?echo +eKenter passwordread passif R Jpass? Z Jpass thenecho system is lockedecho enter password to unlocktrap ]],? E O ? ?Hwhile truedoread passEif R Jpass? Z JpassE then echo system unlockedstty echoe-itelseecho password mismatchfidoneelseecho password mismatchstty echofi

    Ou#u4

    enter the password to lock terminal 7@@@@reKenter the password7@@@@system is lockedenter the password to unlock7@@@@

  • 7/21/2019 FOSS Lab --V Prasad,2013

    37/51

    system unlockedenter the password to lock terminal7@@@@@@@@reKenter the password7@@@@password mismatch

    G.C!"a" a sc!# l" call"$ l" #!'#"!"s ,a !"a$s a l" na2" "n"!"$ an$'u#uss #!'#"!"s

    P!'+!a24

    echo enter a filenameread fileif R Kf Jfile thenset KK ]ls Kl Jfile]

    echo file permission J?echo number of link Jecho user name JEecho owner name Jecho block siMe Jecho date of modification JDecho time of modification JGecho name of file JHelseecho file does not e-itfi

    Ou#u

    ?5enter a filename ?Fa.shfile permission KrwKrKKrKKnumber of links ?user name scowner name scblock siMe DDdate of modification FFOKF?KOtime of modification F7EFname of file ?Fa.sh

    5

    enter a filenametestfile does not e-it

  • 7/21/2019 FOSS Lab --V Prasad,2013

    38/51

    H.W!" a s,"ll sc!# ,a acc"# 'n" '! 2'!" l" na2"s as a!+u2"n an$ c'n"!all ' ,"2 ' u##"!cas"& #!'$"$ ,"y ";s n cu!!"n $!"c'!y.

    P!'+!a24

    clearif R J Ke8 F then Xecho enter the argumentsYe-itfifor i in J@doif R Kf Ji thenecho it is a valid file

    echo Contents of file before convertingcat Jiecho Contents of file after convertingtr PRaKMP PRAK\P < JikZ]ls Ji N tr PRaKMP PRAK\P]mv Ji Jkecho file Ji renamed as J-lselseecho file does not e-istfidone

    Ou#u

    Jsh b.sh testIt is a valid filefile test renamed as T)ST?Fb.sh ?b.awk ?bprg.sh a.sh a.sh Da.sh Ha.sh a? d? first rv T)ST -Jsh b.sh program?file does not e-ist

    O./!" a s,"ll sc!# ,a $s#lay all ," lns ' a l" s#"c"$ as ," !a!+u2"n ' ," sc!#. T," s"c'n$ a!+u2"n& /,c, /s '#'nal& can b" us"$ '

    s#"cy n /,c, ," s"a!c, s ' b"+n n cu!!"n /'!n+ $!"c'!y& -n ","!

    cas"& ," sa!n+ $!"c'!y as /"ll as all s sub$!"c'!"s a all l""ls 2us b"

    s"a!c,"$. T," sc!# n""$ n' nclu$" any "!!'! c,"cn+

    P!'+!a24

  • 7/21/2019 FOSS Lab --V Prasad,2013

    39/51

    if R J Ke8 ? then pwd=tmcat tmelsetmZJ

    echo Jtmfit?Z]ls Kali+ N grep J? N cut Kc ?KH ]ls Kalir Jtm N grep Jt? Ncut Kc DK = techo the links arecat t

    Ou#u

    sh a.sh firstlinks are

    ?EHEOG KrwKrKKrKK ? sc sc ?F FFOKF?KO F?7D firstsccselinu-7J ln first tempsccselinu-7J sh a.sh templinks are?EHEOG KrwKrKKrKK sc sc ?F FFOKF?KO F?7D first?EHEOG KrwKrKKrKK sc sc ?F FFOKF?KO F?7D temp

    ?F.W!" a s,"ll sc!# ,a acc"#s as l"na2" as a!+u2"n an$ $s#lay sc!"a'n 2" l" ";ss an$ $'"s n' s"n$ 'u#u "!!'! 2"ssa+"

    P!'+!a24

    if R J Ke8 F thenecho enter the argumentse-itfiif R ;f J? thentimeZ]ls ;l J? N cut ;c K]echo file J? was created on Jtimeelseecho file J? does not e-istfi

    Ou#u 4

    sh b.sh tempfile temp was created on FFOKF?KO F?7Dsh b.sh temp??

  • 7/21/2019 FOSS Lab --V Prasad,2013

    40/51

    file temp?? does not e-ist

    ??.W!" a s,"ll sc!# ' $s#lay ," cal"n$a! '! cu!!"n 2'n, /, cu!!"n$a"!"#lac"$ by B '! BB $"#"n$n+ 'n /,","! ," $a" ,as 'n" $+ '! /' $+s.

    P!'+!a24dZ]date 9^d]cal = cal?if R Jd Kle O thensed Ps,PJdP,@,P cal?e-itfised Ps,PJdP, @@,P cal?

    Ou#u 4

    anuary FFOSu !o Tu 'e Th #r Sa? E D G H O ?F?? ? ?E ? ? ?D ?G?H ?O F ? E D G H O EF @@

    ?.W!" a s,"ll sc!# ' n$ s2all"s ' 3 nu2b"!s ,a a!" !"a$ !'2 "yb'a!$.

    P!'+!a24

    echo enter first numberread aecho enter second numberread becho enter third numberread cif R Ja Ke8 Jb Ka Jb Ke8 Jc thenecho all numbers are e8uale-itfiif R Ja Klt Jb thens?ZJasZJbelse

  • 7/21/2019 FOSS Lab --V Prasad,2013

    41/51

    s?ZJbsZJafiif R Js? Kgt Jc then

    sZJs?s?ZJcfiecho smallest number is Js?

    Ou#u 4

    enter first number7enter second number7DGenter third number 7smallest number is

    enter first number7Fenter second number7Fenter third number 7Fall numbers are e8ual

    13. W!" a s,"ll sc!# usn+ ";#! c'22an$ ' !"a$ n a s!n+ an$ $s#lay a

    suabl" 2"ssa+" $'"s n' ,a" al"as 1: c,a!ac"!s

    P!'+!a24

    clearecho enter the stringread slZ]e-pr length Js]if R Jl Kgt ?F thenecho string has more than ?F characterselseecho string has less than ?F charactersfi

    Ou#u 4

    enter the stringsaipaulstring has less than ?F charactersenter the stringengineeringstring has more than ?F characters

  • 7/21/2019 FOSS Lab --V Prasad,2013

    42/51

    ?.W!" a s,"ll sc!# ' c'2#u" ," su2 ' nu2b"! #ass"$ ' as a!+u2"n 'nc'22an$ ln" an$ $s#lay ," !"sul.

    P!'+!a24

    clearif R J Ke8 F thenecho no argumentse-itelsesumZFfor i in J@dosumZ]e-pr Jsum 9 Ji]done

    echo sum of the numbers is Jsumfi

    Ou#u

    J sh Gb.sh ?F ?F Fsum of the numbers is FJ sh Gb.sh ?F ?FF FFsum of the numbers is E?F

    ?.A2 ' c'2#u" +!'ss sala!y ' an "2#l'y"" &acc'!$n+ly ' !ul" +"n b"l'/.- basc sala!y s 1H::: ,"n =RA 1: ' basc an$ *A 6: ' basc

    - basc sala!y s 1H::: ,"n =RA H:: an$ *A 67 ' basc

    P!'+!a24

    clearecho enter the basicread basicif R Jbasic Klt ?FFF thenhraZ]echo scaleZ: Jbasic @ F.? N bc]daZ]echo scaleZ: Jbasic @ F.O N bc]elsehraZFFdaZ]echo scaleZ: Jbasic @ F.OH N bc]figsZ]echo scaleZ:Jbasic 9Jhra 9Jda N bc]echo gross Z Jgsecho hra Z Jhra

  • 7/21/2019 FOSS Lab --V Prasad,2013

    43/51

    echo da Z Jda

    Ou#u

    J sh Ha.sh

    enter the basic pay?FFFgross Z FFF.Fhra Z ?FF.Fda Z OFF.FJ sh Ha.shenter the basicFFFFgross Z F?FF.FFhra Z FFda Z ?ODFF.FF

    1I. W!" a s,"ll sc!# ' $"l"" all ln"s c'nann+ a s#"cc /'!$ n 'n" '! 2'!"

    l" su##l"$ as a!+u2"n ' .

    P!'+!a24

    clearif R J Ke8 F thenecho no arguments passede-itfiecho the contents before deletingfor i in J@doecho Jicat Jidoneecho enter the word to be deletedread wordfor i in J@dogrep Kvi Jword Ji = tempmv temp Jiecho after deletingcat Jidone

    Ou#u4

  • 7/21/2019 FOSS Lab --V Prasad,2013

    44/51

    J sh Hb.sh test?the contents before deletingtest?hello rvce

    hello csebangaloremysore cityenter the word to be deletedcityafter deletinghello rvcehello csebangaloreJ sh Hb.shno argument passed

    ?D.W!" a s,"ll sc!# ,a +"s ";"cu"$ $s#lays ," 2"ssa+" ","!

  • 7/21/2019 FOSS Lab --V Prasad,2013

    45/51

    strZ]cat J? N tr P6nP P P]for a in Jstrdoecho 'ord Z Ja/ Count Z ]grep Kc Ja J]done

    Ou#u 4

    J cat testhello rvce cseJ cat test?hello rvce csehello rvce csehelloJ sh ?.sh test test?'ord Z hello/ Count Z E

    'ord Z rvce/ Count Z 'ord Z cse/ Count Z

    ?H.W!" a s,"ll sc!# ,a $""!2n"s ," #"!'$ '! /,c, s#"c"$ us"! s/'!n+ 'n ," sys"2.

    P!'+!a24

    echo X)nter the Login ame of a $serYread namecountZ]who N grep ;wo XJuserY N wc ;c]if R Jcount ;e8 F thenecho Xinvalid userYe-itfiif RJcount ;gt thenecho X!ultiple LoginYelseltZ]who N grep XuserY N cut ;c EKEH]lhZ]echo Jlt N cut ;c ?K]lmZ]echo Jlt N cut ;c K]chZ]date 9^0]cmZ]date 9^!]if R Jcm ;gr Jlm thensmZ]e-pr Jcm KJlm]shZ]e-pr Jch K Jlh]else

  • 7/21/2019 FOSS Lab --V Prasad,2013

    46/51

    smZ]e-pr DF K Jlm KJcm]shZ]e-pr Jch K Jlh ; ?]fiecho X The user is logged in from Jsh hour Jsm minutesYfi

    Ou#u 7

    ?5 )nter the user name 7cse?OThe user is logged in from ? hour F minutes5 )nter the user name7abcInvalid user

    ?O.W!" a s,"ll sc!# ,a !"#'!s ," l'++n+ n ' a s#"c"$ us"! /,n 'n"2nu" a"! ,"@s," l'+s n. T," sc!# au'2acally "!2na"s ," s#"c"$

    us"! $'"s n' l'+n $u!n+ a s#"c"$ #"!'$ ' 2"

    P!'+!a24

    echo )nter the login name of the user7Yread userperiodZFwhile R truedovarZ]who N grep ;w XJuserY]lenZ]echo XJvar N wc ;c]if R Jlen ;gt ? thenecho XJuser logged in Jtm secondsYe-itelsesleep ?tmZ]e-pr Jtm 9 ?]fiif R Jtm ;e8 D? thenecho XJuser did not login within ? minuteYe-itfidone

    Ou#u 4

    )nter the login name of the user 7cse?Ocse?O logged in seconds)nter the login name of the user 7cseF

  • 7/21/2019 FOSS Lab --V Prasad,2013

    47/51

    cseF did not login within ? minute

    8:. W!" a s,"ll sc!# ,a acc"#s /' n"+"!s as s a!+u2"ns an$ c'2#u"s

    ," alu" ' !s nu2b"! !as"$ ' ," #'/"! ' ," s"c'n$ nu2b"!.

    P!'+!a24

    if R J Kne thenecho )rror 7 Invalid no. of arguments.e-itfipwrZ]echo J? Q J N bc]echo J? Q J Z Jpwr

    Ou#u4

    Jsh ??a.sh EQE Z H

    81. W!" a s,"ll sc!# ,a acc"#s a l"na2"& sa!n+ an$ "n$n+ ln" nu2b"!s

    as a!+u2"ns an$ $s#lays all ," ln"s b"/""n ," +"n ln" nu2b"!s.

    P!'+!a24

    if R J Kne E then echo )rror 7 Invalid number of arguments.e-itfiif R J Kgt JE thenecho )rror 7 Invalid range value.e-itfilZ]e-pr JE K J 9 ?]cat J? N tail 9J N head KJl

    Ou#u4

    Jsh ??b.sh test Gabc ?Edef DGHghi O?F??

  • 7/21/2019 FOSS Lab --V Prasad,2013

    48/51

    .W!" a s,"ll sc!# ,a 'l$s l'n+ ln"s n' 9: c'lu2ns. T,us any ln" ,a";c""$s 9: c,a!ac"!s 2us b" b!'"n a"! 9:, aQ s ' b" a##"n$"$ as ,"

    n$ca'n ' 'l$n+ an$ ," #!'c"ssn+ s ' b" c'nnu"$ /, ," !"s$u". T,"

    n#u s ' b" ,!'u+, a "; l" c!"a"$ by ," us"!.

    P!'+!a24

    echo X )nter the filename 76cYread fnfor ln in ]cat Jfn]dolgthZ]echo Jln N wc Kc]lgthZ]e-pr Jlgth K ?]sZ?:eZif R Jlgth Kgt F then

    while R Jlgth Kgt F doecho ]echo Jln N cut Kc JsKJe]66sZ]e-pr Je 9 ?]eZ]e-pr Je 9 F]lgthZ]e-pr Jlgth K F]doneecho Jln N cut Kc Jselseecho Jlnfidoneecho X#ile #olded Y

    OUTPUT

    Jsh ?a.sh)nter the filename 7 test#ile #olded

    E.W!" a a/ sc!# ,a acc"#s $a" a!+u2"n n ," '!2 ' 220$$0yy an$$s#lays n ," '!2 any &2'n, &y"a!. T," sc!# s,'ul$ c,"c ," al$y '

    ," a!+u2"n an$ n ," cas" ' "!!'!& $s#lay a suabl" 2"ssa+".

    B)IVsystem3XclearY5:daZYE?HE?EFE?EFE?E?EFE?EFE?YmoZYA#)B!A+A&+!A`$$LA$S)&*CT*(%)CYmmZsubstr3A+(R?/?/5ddZsubstr3A+(R?//5

  • 7/21/2019 FOSS Lab --V Prasad,2013

    49/51

    yyZsubstr3A+(R?/G/5if3dd = substr3da/KmmK?/5 NN 3mm=?5 NN A+C >Z5print XInvalid dateYelseprint XThe day is ^d 6n The month is ^s 6n

    The year is ^d 6nY/dd/substr3mo/E@mmK/E5yyW

    Ou#u 4

    Jawk Kf ?b.awk ?K?FKFFHThe day is ?FThe month is *CTThe year is FFH

    .W!" an a/ sc!# ' $"l"" $u#lca"$ ln" !'2 a "; l". T," '!$"! ' ,"

    '!+nal ln"s 2us !"2an unc,an+"$.

    P!'+!a24

    B)IVaRn99ZJFW)%Vfor3iZF:i

  • 7/21/2019 FOSS Lab --V Prasad,2013

    50/51

    bangaloreJ awk 0f ?Ea.awk testcollegeBangalore

    .W!" an a/ sc!# ' n$ 'u 'al nu2b"! ' b''s s'l$ n "ac, $sc#ln"as /"ll as 'al b'' s'l$ usn+ ass'ca" a!!ay $'/n abl" as +"n"l"c!cal 39

    2"c,ancal I

    "l"c!cal 7:

    c'2#u"!s 93

    2"c,ancal IH

    cl 167

    c'2#u"!s I9

    P!'+!a24

    B)I Vprint XT*TAL $!B)+ *# B**2S S*L% I )AC0 CAT)*+`YWV booksRJ?9ZJW)% Vfor 3item in books5Vprintf 3X ^s soldZ ^d6nY/item/booksRitemWtotal 9ZbooksRitemWprintf3YTotal books soldZ^dY/total5W

    Ou#u 4

    T*TAL $!B)+ *# B**2S S*L% I )AC0 CAT)*+`electrical ??mechanical ?EGcomputers ?FGcivil ?OHTotal books sold Z D

    D.W!" an a/ sc!# ' c'2#u" +!'ss sala!y ' an "2#l'y"" acc'!$n+ly '!ul" +"n b"l'/ - basc sala!y 1:::: ,"n *A 9H ' the basc an$ =RA

    1H ' basc - basc sala!y 1:::: ,"n *A H: ' the basc an$ =RA

    8: ' basc

    P!'+!a24

    B)I V printf )nter the Basic &ay 7 +s. getline bp < ,dev,tty

  • 7/21/2019 FOSS Lab --V Prasad,2013

    51/51

    if3bp


Recommended