Week 2
Week 2
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.
Cat:----
cat file1
displays contents of file1 on the screen (or window)
without any screen breaks.
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 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.
-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.