0% found this document useful (0 votes)
29 views3 pages

Week 2

Uploaded by

Kalyan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Week 2

Uploaded by

Kalyan Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Week2

a)Log into the system


b)Use the cat command to create a file containing the following data. Call it mytable use
tabs to separate the fields.
1425 Ravi 15.65
4320 Ramu 26.27
6830 Sita 36.15
1450 Raju 21.86
Sol: cat > mytable
1425 Ravi 15.65
4320 Ramu 26.27
6830 Sita 36.15
1450 Raju 21.86

c)Use the cat command to display the file, mytable.


Sol: $cat mytable
1425 Ravi 15.65
4320 Ramu 26.27
6830 Sita 36.15
1450 Raju 21.86
d) Use the vi command to correct any errors in the file, mytable.
Sol: Verify the file with Vi editor Commannds
e) Use the sort command to sort the file mytable according to the first field. Call the
sorted file my table
( same name)
Sol: $sort +1 mytable > mytable
f) Print the file mytable
Sol: cat mytable
1425 Ravi 15.65
1450 Raju 21.86
4320 Ramu 26.27
6830 Sita 36.15

g) Use the cut and paste commands to swap fields 2 and 3 of mytable. Call it my table
(same name)
Sol: $cut -f1 > mytab1
$ cut –f 2 > mytab 2
$cut –f 3 > my tab3
$paste mytab3 mytab2 > mytab4
$paste mytab1 mytab4 > mytable
h)Print the new file, mytable
Sol: $ cat mytable
1425 15.65 Ravi
1450 21.86 Raju
4320 26.27 Ramu
6830 36.15 Sita
i)Logout of the system.

Note… Make Use of following commands

Cat:----

cat to display a text file or to concatenate files

cat file1
displays contents of file1 on the screen (or window)
without any screen breaks.

cat file1 file2


displays contents of file1 followed by file2 on the
screen (or window) without any screen breaks.
cat file1 file2 > file3 creates file3 containing file1 followed by file2

Sort :----
The "sort" command sorts information piped into it. There are several options that
let you sort information in a variety of ways.
ps -ef | sort

The most important options in Sort :

The following list describes the options and their arguments that may be used to control
how sort functions.

 - Forces sort to read from the standard input. Useful for reading from pipes and
files simultaneously.
 -c Verifies that the input is sorted according to the other options specified on the
command line. If the input is sorted correctly then no output is provided. If the
input is not sorted then sort informs you of the situation. The message resembles
this.

 sort: disorder: This line not in sorted


order.


 -m Merges the sorted input. sort assumes the input is already sorted. sort
normally merges input as it sorts. This option informs sort that the input is
already sorted, thus sort runs much faster.
 -o output Sends the output to file output instead of the standard output. The output
file may be the same name as one of the input files.
 -u Suppress all but one occurrence of matching keys. Normally, the entire line is
the key. If field or character keys are specified, then the suppressing is done based
on the keys.
 -y kmem Use kmem kilobytes of main memory to initially start the sorting. If
more memory is needed, sort automatically requests it from the operating system.
The amount of memory allocated for the sort impacts the speed of the sort
significantly. If no kmem is specified, sort starts with the default amount of
memory (usually 32K). The maximum (usually 1 Megabyte) amount of memory
may be allocated if needed. If 0 is specified for kmem, the minimum (usually
16K) amount of memory is allocated.
 -z recsz Specifies the record size used to store each line. Normally the recsz is set
to the longest line read during the sort phase. If the -c or -m options are specified,
the sort phase is not performed and thus the record size defaults to a system size.
If this default size is not large enough, sort may abort during the merge phase. To
alleviate this problem you can specify a recsz that will allow the merge phase to
run without aborting.

You might also like