Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet34/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   30   31   32   33   34   35   36   37   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

Command
Result
head file.txt
Output first 10 lines of file.txt
tail file.txt
Output last 10 lines of file.txt
head –c 100 file.txt
Output first 100 bytes of file.txt
head –n –3 file.txt
Output first 11 lines of file.txt (all but the last three lines)
tail –n 5 file.txt
Output last 5 lines of file.txt
tail –c 
+
100 file.txt
Output all characters of file.txt starting at the 100th byte


Navigating the Linux File System

89
line of the difference. You can force cmp to skip over a specified number of bytes for each 
file or stop after reaching a specified limit. The following instruction
cmp file1 file2 -i 100:150 -n 1024
will compare file1 and file2, starting at byte 101 of file1 and 151 of file2, comparing 1024 
bytes.
The comm instruction expects to receive two files that contain sorted content. If the 
content is not sorted, while comm will still work, you may not get the results you hope 
for. The comm instruction works through the two files, comparing them line-by-line and 
returns for each line whether it appeared in the first file, the second file, or both files. This 
output is organized into columns where column 1 features lines only appearing in the 
first file, column 2 features lines common to both files, and column 3 features lines only 
appearing in the second file.
A related program to diff, cmp, and comm is 
uniq
. Unlike these previous commands, 
uniq operates on a single file, searching for consecutive duplicate lines. Based on the 
parameters supplied, you can use uniq to remove any such duplicates although uniq does 
not overwrite the file but instead outputs the file without the duplicates. You would then 
redirect the output to a new file, as in
uniq file.txt > filewithoutduplicates.txt
As uniq only compares adjacent lines, it would not find duplicate lines that do not appear 
one after the other. Options allow you to output the found duplicates or count the number 
of duplicates rather than outputting the file without the duplicates, and you can ignore case 
or skip over characters.
3.3.7 File Manipulation Commands
The 
join
command allows you to join two files together when the files contain a common 
value (field) per line. If this is the case, when the two files each have a row that contains 
that same value, then those two lines are joined together. As an example, consider two files, 
first.txt and last.txt, each of which contain a line number followed by a person’s first or last 
name. Joining the two files would append the value in last.txt to the value found in first.txt 
for the given line number. If we had for instance in the two files:
1. Frank 
1. Zappa
2. Tommy 
2. Mars
then the join would yield
1. Frank Zappa
2. Tommy Mars


90

Linux with Operating System Concepts
For lines that do not share a common value, those lines are not joined. The options 
-1 
NUM
and 
-2 
NUM
allow you to specify which fields should be used on the first and second 
files, respectively, where 
NUM
is the field number desired. The option -i would cause join 
to ignore case if the common values included letters. The option 
-e 
STRING
would cause 
STRING
to be used in case a field was empty, and 
-a 1
or 
-a 2
would output lines from 
the first or second file which did not contain a match to the other file.
Another means of merging files together is through the 
paste
command. Here, the 
contents of the files are combined, line by line. For instance, 
paste 

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish