Tuesday, 13 December 2016

FOSS LAB PROGRAM 1 & 2

PROGRAM-1
SESSION-1
I.                   Log into the system.
II.                Use vi editor to create a file called myfile.txt which contains some text.
III.             Correct typing errors during creation.
IV.             Save the file.
V.                Logout of the system.
Source code:
 a. Type the username and password as "student".
 b. Create a file "myfile.txt" containing some text like: "WELCOME TO UNIX". Implement in the following way:- In the UNIX command prompt type:- vi myfile.txt

  • A file is created. It opens a new window in which no text can be read (or) write since, it is in command mode.
  • So, the mode is changed to "Insert".
  • Now type the required text like:-"WELCOME TO UNIX".
 c.        There are no errors in the following creation.
 d.        To save the file, press escape and type ":x" (or) to save and exit from the file type ":wq".
                        *To display the file type:- cat <myfile.txt (or) cat myfile.txt
e.         Go to system tools--->logout--->press logout.
SESSION-2
a.       Log into the system.
b.      Open the file created in session 1
c.       Add some text
d.      Change some text
e.       Delete some text
f.       Save the changes
g.      Logout of the system
Source code:
I.                   Enter userid and password as “student”.
II.                 To view the existed file type:- vi myfile.txt.
III.             To add information, change the command mode to “Insert” by using “Insert button”.
Add some information like: “welcome to gvpcew, cse”
IV.             If you want to change the text it can be changed as mentioned in the third step.
V.                 Text can be deleted too.
VI.             To save the file, press “escape” and “:wq”.
VII.          Go to system tools--->logout--->press logout.

PROGRAM-2
I.                   Log into the system
II.                Use the cat command to create a file containing the following data. Call it my table use tabs to separate the fields.
1425                ravi                  15.65
4320                ramu                26.27
6830                sita                   36.15
           1450                 raju                  21.86
III.             Use the cat command to display the file, mytable.
IV.             Use the vi command to correct any errors in the file, mytable.
V.                Use the sort command to sort the file mytable according to the first field. Call the sorted file mytable (same name).
VI.             Print the file mytable
VII.          Use the cut and paste commands to swap fields 2 and 3 of mytable. Call it mytable (same name)
VIII.       Print the new file, mytable.
IX.             Logout of the system.
Source code:
a.       Enter userid and password as student.
b.      To create a file, cat >mytable.txt
1425                      ravi                  15.65
4320                      ramu                26.27
6838                      sita                   36.15
1450                      raju                  21.86
      To save the file, press “ctrl+D”.
c.       To display the file, cat mytable.txt
1425                      ravi                  15.65
4320                      ramu                26.27
6838                      sita                   36.15
     1450                       raju                  21.86
d.      Type vi mytable.txt and correct any errors if any and save the file by pressing “escape” and “:wq”.
e.       To sort the file according to first field, use either sort mytable.txt (or) sort –n mytable.txt
1425                      ravi                  15.65
1450                      raju                  21.86  
4320                      ramu                26.27
6830                      sita                   36.15
      Save sorted table as “mytable” as “sort mytable.txt>mytable”
f.       To print the table, cat mytable
1425                      ravi                  15.65
1450                      raju                  21.86
4320                      ramu                26.27  
6830                      sita                   36.15
g.      To cut and save the 2nd  field use “cut –f2 mytable>file1”
ravi
raju
ramu
sita
      To cut and save the 1st and 3rd fields use
“cut –f1,3 mytable>file2”
                  1425                15.65
                  1450                21.86
                  4320                26.27
                  6830                36.15
Using paste command, the 2nd and 3rd fields are swapped. To paste and save, use
“paste file2 file1>mytable.txt”

h.      To print the new file in which 2nd and 3rd fields of original table are swapped, use
cat mytable.txt
1425                      15.65   ravi
1450                      21.86   raju
4320                      25.27   ramu
6830                      36.15   sita
i.        Go to system toolsàlogoutàpress logout.


No comments:

Post a Comment