0% found this document useful (0 votes)
13 views

LP Lab Part1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

LP Lab Part1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

LINUX PROGRAMMING LAB

• Dr. P.V.S. Siva Prasad


Associate Professor
Mobile Number: 8555990645
Email : [email protected]
Lab Experiment 1

1.Log in to the system


2.Use Vi editor to create a file called myfile.txt which contain some
text.
3.Correct typing errors during creation
4.Save the file
5.Logout of the file
Lab Experiment 2

1.Log into the system


2.Open the file created in Experiment 1
3.Add some text
4.Change some text
5.delete some text
6.Save the changes
7.Logout of the system
cat - “cat" this command is used to create, view and
concatenate files.
Syntax cat [argument] [specific file]

cat /etc/passwd - This command displays the


"/etc/passwd" file on your
screen.
cat file1 file2 file3 > file4
This command combines the contents of the first
three files into the fourth file.
Lab Experiment 3
a)Use the cat command to create a file containing the
following data. Call it mutable use tabs to separate the
fields

1425 ravi 15.65


4320 ramu 26.27
6830 sita 36.15
1450 raju 21.86

b)use the cat command to display the file, my table

c)use the vi command to correct any errors in the file, my


table
wc
The wc command gives us useful information about a
file or input it receives via pipes.
wc -l filename – Number of Lines
wc -w filename – Number of Words
wc -c filename – Number of Charecters

clear - clear all the previous commands that were


ran in the current terminal.
sort
To sort the names in alphabetical order
Syntax: sort filename
1. sort file name : By default ascending order
2. -r : this option is use to sort in descending order, you
can use the "-r" option:
3. -n : this option To sort the numbers in ascending order,
To sort the
4. -t : option is used to specify the field separator
5.-k : option is used to specify the field to use for sorting,
Example: sort -t ',' -k 2 employees.txt
Example: sort -t ',' -k 2 unsorted.txt > sorted.txt
cut
It is used to cut a specific sections by byte position, character, and
field and writes them to standard output

Syntax : cut OPTION... [FILE]...


-c Selects only the characters specified
in LIST (e.g., -c 1-3,7).
-d Uses DELIM as the field delimiter
character instead of the tab character.
-f, –fields=LIS Selects only the fields specified in
LIST, separated by the delimiter character
(default is tab).
Paste command
allows to merge multiple files or lines of text into a single output
Syntax and Options:
$ paste [options] [file1-name] [file2-name] ...
options−
-s : This option causes the paste command to merge files
that the first line of the first file will be combined with
the first line of the second file and so on.
-u This option causes the paste command to remove any
duplicate lines when merging files.

Example:
paste -d ',' cut_fields.txt > paste_fields.txt
Lab Experiment 4
•use the appropriate commands to determine ur login shell
•use the /etc/passwd file to verify the result of step b.

• use the who command redirect the result to a file called


myfile1. Use the more command to see the contents of
myfile1.

• Use the date and who commands in sequence ?(in one line)
such that the output of date will display on the screen and

the output of who will be redirected to a file called my file2.

• Use the more command to check the contents of myfile2.


Lab Experiment 5

• use the sort command to sort the file my table


according to the first field. Call the sorted file my
table(same name)

• print the file my table

• use the cut & paste commands to swap fields 2 and


3 my table. Call it mytable(same name) print the
new file, my table

You might also like