Ravindra BagaleCourses & study guides English

Linux cut, sort, uniq, tr, paste आणि diff Commands उदाहरणांसह

Raw text गोंधळलेला असतो. एक column निवडायचा, sort करायचा, duplicates काढायचे, मोजायचे, characters बदलायचे, files शेजारी ठेवायच्या आणि काय बदललं ते बघायचं. cut, sort, uniq, tr, paste आणि diff ही कामं करतात. मिळून 'माझ्या server ला मारणारे top 10 IPs' सारख्या प्रश्नांना एका line मधे उत्तर देतात.

या chapter मध्ये तुम्ही काय शिकाल

  • cut ने columns आणि characters निवडा
  • Text, numbers, sizes आणि column ने sort
  • uniq ने duplicates काढा आणि मोजा
  • tr ने characters बदला किंवा delete
  • paste, join, comm ने files शेजारी जोडा
  • diff ने files compare आणि patches

1. रोजचं उदाहरण: वर्गाचा result sheet

हे का लागतं?

कुलकर्णी सरांकडे result list आहे: roll number, नाव, शहर आणि marks. त्यांना फक्त नावं हवीत (column निवडा), toppers आधी (marks ने sort), प्रत्येक शहरातून किती विद्यार्थी (duplicates मोजा), certificate साठी नावं capitals मधे (characters बदला), जुनी list नव्या शेजारी, आणि re-checking नंतर काय बदललं (compare).

हे काय आहे?

Column निवडणं = cut. Toppers आधी = sort -k4 -nr. शहरानुसार count = sort | uniq -c. Capitals = tr a-z A-Z. शेजारी = paste. काय बदललं = diff.

कसं करायचं (step by step)

Classic count pipelineRaw log linescut हवा तो field निवडतोsort सारख्या values एकत्र आणतोuniq -c प्रत्येक group मोजतोsort -nr सगळ्यात मोठं आधीhead top N दाखवतो
uniq फक्त शेजारच्या lines जोडतो, म्हणून uniq आधी नेहमी sort.

2. cut: columns किंवा characters निवडा

हे का लागतं?

CSV files, /etc/passwd आणि अनेक logs मधे fields एका character ने वेगळे असतात. अनेकदा एकच field हवा असतो.

हे काय आहे?

cut -d',' -f2 comma ने वेगळा field 2. -f1,3 fields 1 आणि 3, -f2- 2 पासून शेवटपर्यंत. -c1-5 characters 1 ते 5. --complement निवडलेले सोडून बाकी. Default delimiter TAB. cut अनेक spaces एक मानत नाही; space-aligned output साठी awk किंवा आधी tr -s ' '.

कसं करायचं (step by step)

  1. /etc/passwd मधून usernames.
cut -d: -f1 /etc/passwd | head -3

Output:

root
bin
daemon

याचा अर्थ: Fields colons ने वेगळे.

  1. User आणि shell.
cut -d: -f1,7 /etc/passwd | tail -2

Output:

ravi:/bin/bash
nginx:/sbin/nologin

याचा अर्थ: Output मधे तोच delimiter.

  1. CSV मधून city column.
cut -d, -f2 sales.csv | tail -n +2 | head -3

Output:

Pune
Nashik
Pune

याचा अर्थ: tail -n +2 header काढतो.

  1. प्रत्येक log line चे पहिले 10 characters (date).
cut -c1-10 app.log | head -2

Output:

2026-10-25
2026-10-25

याचा अर्थ: -c character position ने.

  1. Password column सोडून सगळं.
cut -d, -f3 --complement users.csv | head -2

Output:

id,name,city
1,Aditi,Pune

याचा अर्थ: --complement उलटी निवड (GNU cut).

  1. Space-aligned output: आधी squeeze.
ps aux | tr -s ' ' | cut -d' ' -f2,11 | head -2

Output:

PID COMMAND
1 /sbin/init

याचा अर्थ: tr -s अनेक spaces एक करतो, मग cut split करू शकतो.

3. sort: lines क्रमाने लावा

हे का लागतं?

Sorted data वाचायला सोपा, आणि uniq, comm, join सारख्या tools ना sorted input लागतो.

हे काय आहे?

sort default text म्हणून क्रम लावतो. -n numeric, -r उलटा, -h human sizes (2K, 5M, 1G), -k2 field 2 ने, -t, field separator, -u unique, -f case ignore, -V version क्रम (v1.2 < v1.10), -o file output लिहितो (त्याच file वर पण safe), -c sorted आहे का तपासतो. -k2,2 म्हणजे फक्त field 2; -k2 म्हणजे field 2 पासून line शेवटपर्यंत.

Optionउपयोग
-nNumbers: 10 आधी 9
-h512K 2G सारखे sizes
-rउलटा
-t, -k3,3CSV च्या field 3 ने
-uDuplicates काढा
-VVersions
-o fFile f मधे लिहा

कसं करायचं (step by step)

  1. Text sort vs number sort.
printf '10\n9\n100\n' | sort; printf '10\n9\n100\n' | sort -n

Output:

10
100
9
9
10
100

याचा अर्थ: -n शिवाय '1' < '9' म्हणून 100 आधी.

  1. Marks नुसार, सगळ्यात जास्त आधी.
sort -t, -k4,4nr marks.csv | head -3

Output:

7,Sneha,Pune,98
3,Imran,Mumbai,95
9,Anna,Goa,91

याचा अर्थ: Field 4, numeric, उलटा.

  1. सगळ्यात मोठे folders.
du -sh /var/log/* | sort -rh | head -3

Output:

1.2G /var/log/journal
300M /var/log/nginx
12M /var/log/dnf.log

याचा अर्थ: -h K, M, G समजतो.

  1. Version क्रम.
printf 'v1.10\nv1.2\nv1.9\n' | sort -V

Output:

v1.2
v1.9
v1.10

याचा अर्थ: -V माणसं versions वाचतात तसं sort.

  1. Unique sorted cities.
cut -d, -f3 marks.csv | tail -n +2 | sort -u

Output:

Goa
Mumbai
Pune

याचा अर्थ: sort | uniq सारखंच.

  1. File in place safely sort.
sort -o names.txt names.txt

Output:

(no output)

याचा अर्थ: sort names.txt > names.txt file रिकामी करेल; -o safe.

4. uniq: duplicates काढा आणि मोजा

हे का लागतं?

सगळ्यात जास्त login कोणी? कोणता error परत परत? Repeats मोजणं हे log analysis चं हृदय.

हे काय आहे?

uniq शेजारच्या सारख्या lines जोडतो. म्हणून जवळजवळ नेहमी आधी sort. -c count जोडतो, -d फक्त repeated lines, -u फक्त एकदा आलेल्या, -i case ignore, -f1 पहिला field skip. Famous pipeline sort | uniq -c | sort -nr | head.

कसं करायचं (step by step)

  1. आधी sort का.
printf 'a\nb\na\n' | uniq; printf 'a\nb\na\n' | sort | uniq

Output:

a
b
a
a
b

याचा अर्थ: Sort शिवाय दोन a शेजारी नाहीत.

  1. शहरानुसार विद्यार्थी.
cut -d, -f3 marks.csv | tail -n +2 | sort | uniq -c

Output:

      2 Goa
      4 Mumbai
      6 Pune

याचा अर्थ: Number म्हणजे count.

  1. Access log मधले top 3 IPs.
cut -d' ' -f1 access.log | sort | uniq -c | sort -nr | head -3

Output:

    812 10.0.0.7
    430 10.0.0.2
     95 49.36.12.4

याचा अर्थ: 10.0.0.7 ने 812 requests.

  1. फक्त duplicate emails.
sort emails.txt | uniq -d

Output:

aditi@example.com

याचा अर्थ: हे एकापेक्षा जास्त वेळा.

  1. फक्त एकदा आलेल्या.
sort emails.txt | uniq -u | wc -l

Output:

148

याचा अर्थ: 148 emails फक्त एकदा.

  1. Error प्रकार मोजा.
grep -o 'ERROR [A-Za-z]*' app.log | sort | uniq -c | sort -nr

Output:

     41 ERROR timeout
      9 ERROR auth

याचा अर्थ: grep -o फक्त match print करतो (पुढचा chapter).

5. tr: characters बदला, squeeze आणि delete करा

हे का लागतं?

नावं uppercase हवीत, Windows line ends काढायचे, commas चं new lines करायचं किंवा अनेक spaces squeeze करायचे.

हे काय आहे?

tr फक्त stdin वाचतो (file नाव argument नाही) आणि एकेका character वर काम करतो. tr 'a-z' 'A-Z' case बदलतो, tr -d '\r' characters delete, tr -s ' ' repeats एक करतो, tr ',' '\n' commas चे new lines, tr -cd '[:digit:]' फक्त digits ठेवतो (-c = complement). Classes: [:upper:] [:lower:] [:digit:] [:space:] [:alnum:] [:punct:].

कसं करायचं (step by step)

  1. Uppercase.
echo 'pune city' | tr 'a-z' 'A-Z'

Output:

PUNE CITY

याचा अर्थ: प्रत्येक अक्षर capital मधे.

  1. Windows line ends काढा.
tr -d '\r' < win.sh > unix.sh && cat -A unix.sh | head -1

Output:

#!/bin/bash$

याचा अर्थ: ^M गेलं. dos2unix सारखं काम.

  1. Spaces squeeze.
echo 'a    b   c' | tr -s ' '

Output:

a b c

याचा अर्थ: अनेक spaces एक.

  1. Comma list lines मधे.
echo 'web1,web2,db1' | tr ',' '\n'

Output:

web1
web2
db1

याचा अर्थ: आता sort किंवा loop करता येतं.

  1. Phone number मधून फक्त digits.
echo '+91 (98220) 12-345' | tr -cd '[:digit:]'

Output:

919822012345

याचा अर्थ: -c म्हणजे 'हे सोडून', -d delete.

  1. PATH एक प्रति line.
echo "$PATH" | tr ':' '\n'

Output:

/usr/local/bin
/usr/bin
/bin

याचा अर्थ: वाचायला आणि तपासायला सोपं.

6. paste: files शेजारी जोडा

हे का लागतं?

नावं एका file मधे, emails दुसऱ्यात; एक list हवी.

हे काय आहे?

paste line 1 सोबत line 1, line 2 सोबत 2, TAB ने जोडतो. -d, comma. -s एका file च्या सगळ्या lines एका line मधे. paste -sd+ bc साठी बेरीज बनवतो.

कसं करायचं (step by step)

  1. नावं आणि emails शेजारी.
paste -d, names.txt emails.txt

Output:

Aditi,aditi@ex.com
John,john@ex.com

याचा अर्थ: Line 1 सोबत line 1, line 2 सोबत 2.

  1. सगळ्या lines एका comma list मधे.
paste -sd, servers.txt

Output:

web1,web2,db1

याचा अर्थ: Arguments बनवायला उपयोगी.

  1. paste आणि bc ने बेरीज.
paste -sd+ amounts.txt | bc

Output:

12750

याचा अर्थ: 4500+3200+5050 बनवतो, bc बेरीज करतो.

7. join: दोन files key वर merge

हे का लागतं?

एका file मधे ids आणि नावं, दुसऱ्यात ids आणि शहरं; database join सारखी एक table हवी.

हे काय आहे?

join FILE1 FILE2 default field 1 वर join. -t, separator, -1 2 -2 3 key fields, -a1 file 1 मधल्या न जुळणाऱ्या lines ठेवतो (left join). दोन्ही files key वर sorted हव्यात.

कसं करायचं (step by step)

  1. id वर दोन files join.
join -t, <(sort ids_names.csv) <(sort ids_city.csv)

Output:

1,Aditi,Pune
2,John,London

याचा अर्थ: दोन्ही files key वर sorted हव्यात.

  1. Left join: न जुळलेल्या ठेवा.
join -t, -a1 <(sort ids_names.csv) <(sort ids_city.csv)

Output:

1,Aditi,Pune
2,John,London
3,Mei

याचा अर्थ: Mei ला शहर नाही, तरी ठेवली.

8. comm: दोन sorted lists compare

हे का लागतं?

जुनी server list vs नवी: काय जोडलं, काढलं, राहिलं?

हे काय आहे?

comm तीन columns print करतो: फक्त file 1, फक्त file 2, दोन्हीत. -1 -2 -3 columns लपवतात: -12 common, -23 फक्त file 1, -13 फक्त file 2. Inputs sorted हवेत.

कसं करायचं (step by step)

  1. दोन्ही lists मधले servers.
comm -12 <(sort old.txt) <(sort new.txt)

Output:

web1
web2

याचा अर्थ: दोन्हीत common.

  1. काढलेले servers.
comm -23 <(sort old.txt) <(sort new.txt)

Output:

db-old

याचा अर्थ: फक्त जुन्या list मधे.

  1. जोडलेले servers.
comm -13 <(sort old.txt) <(sort new.txt)

Output:

web3

याचा अर्थ: फक्त नव्या list मधे.

9. diff: नेमकं काय बदललं ते बघा

हे का लागतं?

Config बदलाने site तुटली. Backup आणि live file मधे कोणती line बदलली ते शोधायचं.

हे काय आहे?

diff a b सांगतो a चं b करायला कोणत्या lines बदलायच्या. -u unified format (Git वापरतो तो): - म्हणजे काढलेली, + जोडलेली, @@ line numbers. -y शेजारी, -q फक्त वेगळ्या आहेत का, -r folders compare, -i case ignore, -w spaces ignore. Exit code: 0 same, 1 वेगळ्या, 2 problem. patch diff -u file लागू करतो. cmp binary files byte by byte; vimdiff colours दाखवतो.

कसं करायचं (step by step)

  1. दोन configs चा unified diff.
diff -u nginx.conf.bak nginx.conf

Output:

--- nginx.conf.bak
+++ nginx.conf
@@ -12,3 +12,3 @@
     listen 80;
-    root /var/www/shop;
+    root /var/www/shopp;
     index index.html;

याचा अर्थ: कोणीतरी shopp लिहिलं. त्यामुळे site तुटली.

  1. फक्त विचारा: वेगळ्या आहेत का?
diff -q a.txt b.txt; echo $?

Output:

Files a.txt and b.txt differ
1

याचा अर्थ: Exit code 1 म्हणजे वेगळ्या. Scripts मधे उपयोगी.

  1. शेजारी.
diff -y --width=50 old.txt new.txt

Output:

web1          web1
web2        | web3
db1           db1

याचा अर्थ: | बदललेली line.

  1. दोन folders compare.
diff -rq /etc/nginx /backup/nginx

Output:

Files /etc/nginx/nginx.conf and /backup/nginx/nginx.conf differ
Only in /etc/nginx/conf.d: new.conf

याचा अर्थ: बदललेल्या आणि जास्तीच्या files.

  1. Patch बनवा आणि लावा.
diff -u app.conf.orig app.conf > fix.patch && patch app.conf.orig < fix.patch

Output:

patching file app.conf.orig

याचा अर्थ: आता orig file मधे तोच बदल.

  1. दोन servers चं output compare.
diff <(ssh web1 rpm -qa | sort) <(ssh web2 rpm -qa | sort)

Output:

< openssl-3.0.7-1
> openssl-3.0.8-1

याचा अर्थ: <( ) मुळे diff commands compare करू शकतो.

10. cmp: files byte by byte compare

हे का लागतं?

Binaries, images किंवा archives साठी line diff चा अर्थ नाही. एकसारख्या आहेत का आणि कुठे वेगळ्या ते हवं.

हे काय आहे?

cmp a b पहिला वेगळा byte आणि line print करतो. -s शांत (फक्त exit code: 0 same, 1 वेगळ्या). -l प्रत्येक वेगळा byte. Downloads तपासायला अनेकदा sha256sum चांगला.

कसं करायचं (step by step)

  1. दोन binaries compare.
cmp app-v1.bin app-v2.bin

Output:

app-v1.bin app-v2.bin differ: byte 1025, line 3

याचा अर्थ: पहिला फरक byte 1025 ला.

  1. Script मधे शांत check.
cmp -s backup.tar live.tar && echo identical || echo changed

Output:

identical

याचा अर्थ: फक्त exit code.

11. अनेक industries मधली खरी उदाहरणं

हे का लागतं?

तेच Linux skill प्रत्येक प्रकारच्या company मध्ये लागतं. वेगवेगळ्या ठिकाणी पाहिलं की लक्षात राहतं.

हे काय आहे?

प्रत्येक row म्हणजे एक काल्पनिक team. कोण हे वापरतं आणि कसं ते दाखवते.

कसं करायचं (step by step)

Team आणि शहरते कसं वापरतातCommand
Rohit, security, HyderabadAccess logs मधून top attacking IPscut -d' ' -f1 access.log | sort | uniq -c | sort -nr | head
Emma, retail BI, ParisCSV column मधून daily sales बेरीजcut -d, -f4 sales.csv | tail -n +2 | paste -sd+ | bc
Kenji, infra, Tokyoदोन servers मधल्या package lists comparediff <(rpm -qa|sort) <(ssh b rpm -qa|sort)
Pooja, HR tech, ChennaiDuplicate employee emailssort emails.txt | uniq -d
Diego, logistics, MadridImport आधी Windows CSV exports साफtr -d '\r' < export.csv > clean.csv
Zainab, cloud FinOps, LagosBilling मधे आहेत पण inventory मधे नाहीत अशी instancescomm -23 billing.txt inventory.txt

12. नेहमीच्या errors आणि त्यांचे fixes

हे का लागतं?

हे errors सगळ्यांना येतात. कारण माहीत असलं की तास वाचतात.

हे काय आहे?

आधी नेमका message वाचा. मग खालच्या row शी जुळवा.

कसं करायचं (step by step)

दिसणारा errorका होतंFix कसा करायचा
uniq shows duplicates still thereInput sorted नव्हताuniq आधी sort.
sort file | uniq -c
sort puts 100 before 9Text sort, numeric नाही-n जोडा (sizes साठी -h).
sort -n nums.txt
File became empty after sort file > filesort वाचायच्या आधी > file रिकामी करतोsort -o वापरा.
sort -o file file
cut: the delimiter must be a single character-d ला दोन characters दिलेएक character किंवा awk -F.
awk -F'::' '{print $2}' f
cut prints the whole lineत्या line मधे delimiter नाही (default TAB)-d नीट द्या; अशा lines skip करायला -s.
cut -d, -f2 -s data.csv
tr: extra operand 'file.txt'tr file नावं घेत नाहीFile tr मधे redirect करा.
tr a-z A-Z < file.txt
join: file 1 is not in sorted orderjoin ला दोन्ही inputs key वर sortedदोन्ही त्याच field वर sort.
join <(sort a) <(sort b)
comm shows wrong resultsInputs sorted नाहीत, किंवा वेगळ्या locale नेदोन्ही त्याच LC_ALL ने sort.
LC_ALL=C sort a > a.s
diff shows every line changedएका file मधे Windows line ends (\r)--strip-trailing-cr किंवा tr -d '\r'.
diff --strip-trailing-cr a b
sort -k2 sorts wrongly-k2 म्हणजे field 2 ते शेवट; separator set नाही-t आणि -k2,2 वापरा.
sort -t, -k2,2 f.csv

13. Troubleshooting step by step

हे का लागतं?

Text pipeline चुकीचं उत्तर देत असेल तर एक एक step चालवा आणि प्रत्येक output बघा.

हे काय आहे?

वरून खाली जा. ज्या step ला problem दिसतो तिथे थांबा.

कसं करायचं (step by step)

  1. Raw input आणि hidden characters बघा.
head -3 data.csv | cat -A
  1. Delimiter आणि field तपासा.
head -3 data.csv | cut -d, -f2
  1. गरज असेल तिथे numeric sort आहे का.
cut -d, -f4 data.csv | sort -n | tail -3
  1. uniq ला sorted input मिळाला का.
cut -d, -f3 data.csv | sort | uniq -c
  1. Locale surprises fix.
LC_ALL=C sort file | head
  1. diff फक्त line ends मुळे नाही ना.
diff --strip-trailing-cr -q a b

14. Lab 1: Web log मधून top visitors report

हे का लागतं?

Classic count pipeline step by step बनवा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Sample log बनवा.
mkdir -p ~/lab8 && cd ~/lab8 && for i in $(seq 1 300); do echo "10.0.0.$((i%4)) - GET /p$((i%5)) $((i%7==0?500:200))"; done > access.log; head -2 access.log

Output:

10.0.0.1 - GET /p1 200
10.0.0.2 - GET /p2 200
  1. IP field निवडा.
cut -d' ' -f1 access.log | head -2

Output:

10.0.0.1
10.0.0.2
  1. प्रत्येक IP मोजा.
cut -d' ' -f1 access.log | sort | uniq -c

Output:

     75 10.0.0.0
     75 10.0.0.1
     75 10.0.0.2
     75 10.0.0.3
  1. 500 errors असलेली top pages.
grep ' 500$' access.log | cut -d' ' -f4 | sort | uniq -c | sort -nr | head -3

Output:

     9 /p0
     9 /p1
     8 /p4
  1. Report save.
cut -d' ' -f1 access.log | sort | uniq -c | sort -nr > top-ips.txt && wc -l top-ips.txt

Output:

4 top-ips.txt

15. Lab 2: diff ने बिघडलेला config बदल शोधा

हे का लागतं?

Backup बनवा, line बदला, शोधा आणि patch ने undo करा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Config आणि backup.
cd ~/lab8 && printf 'port=8080\nroot=/srv/shop\nmode=prod\n' > app.conf && cp app.conf app.conf.bak

Output:

(no output)
  1. चूक करा.
sed -i 's#/srv/shop#/srv/shopp#' app.conf

Output:

(no output)
  1. शोधा.
diff -u app.conf.bak app.conf

Output:

-root=/srv/shop
+root=/srv/shopp
  1. Reverse patch बनवा आणि लावा.
diff -u app.conf app.conf.bak > undo.patch; patch app.conf < undo.patch

Output:

patching file app.conf
  1. जुळतात का.
diff -q app.conf app.conf.bak && echo same

Output:

same

Ravindra Bagale's Tip

Remember the golden pipeline: cut | sort | uniq -c | sort -nr | head. It answers 'what is the most common X?' for IPs, URLs, users, errors and status codes in seconds.

16. नेहमी विचारले जाणारे प्रश्न

प्र. uniq आधी sort का?

uniq फक्त आधीच्या line शी compare करतो. Sort सारख्या lines एकत्र आणतो.

प्र. cut की awk?

एका fixed delimiter साठी cut सोपा आणि fast. अनेक spaces, conditions, maths साठी awk.

प्र. sort मधे -k2,2 म्हणजे?

Key field 2 ला सुरू आणि संपतो. ,2 शिवाय key line शेवटपर्यंत.

प्र. दोन servers वर sort क्रम वेगळा का?

Locale. en_US.UTF-8 आणि C वेगळं sort करतात. Byte क्रमासाठी LC_ALL=C.

प्र. tr words बदलू शकतो का?

नाही, फक्त एकेक character. Words साठी sed.

प्र. diff चा exit code?

0 same, 1 वेगळ्या, 2 error. Scripts त्याने ठरवतात.

प्र. comm vs diff?

comm ला sorted input लागतो आणि set सारखे columns (फक्त A, फक्त B, दोन्ही). diff क्रमाने edits.

प्र. Unique values कशा मोजायच्या?

sort -u file | wc -l.

17. मुलाखत प्रश्न आणि उत्तरं

Beginner level

प्र. /etc/passwd चा पहिला field कसा print कराल?

cut -d: -f1 /etc/passwd.

प्र. Numbers नीट कसे sort कराल?

sort -n (जास्त आधी साठी -r).

प्र. Lowercase चं uppercase कसं?

tr 'a-z' 'A-Z' किंवा tr '[:lower:]' '[:upper:]'.

प्र. दोन files मधले फरक कसे बघाल?

diff -u old new.

Mid level level

प्र. Access log मधले top 5 IPs.

cut -d' ' -f1 access.log | sort | uniq -c | sort -nr | head -5 (किंवा awk '{print $1}').

प्र. CSV 3rd column ने numeric sort.

sort -t, -k3,3n file.csv.

प्र. A मधे आहेत पण B मधे नाहीत अशा lines.

comm -23 <(sort A) <(sort B), किंवा grep -Fxv -f B A.

प्र. Script मधून Windows CRLF काढा.

tr -d '\r' < in > out, sed -i 's/\r$//' किंवा dos2unix.

Senior level

प्र. 50 GB file sort करताना No space left. Fix?

sort /tmp मधे temp files वापरतो. -T /bigdisk, --buffer-size, --parallel, आणि speed साठी LC_ALL=C; किंवा split करून sort -m ने merge.

प्र. UTF-8 locale server वर sort नंतर uniq -c counts चुकीचे का येऊ शकतात?

Locale collation काही characters सारखे मानतो किंवा विचित्र क्रम लावतो. Exact byte comparison साठी sort आणि uniq दोन्हीला LC_ALL=C.

प्र. 50 servers वर config drift कसा शोधाल?

प्रत्येकातून checksum किंवा file घ्या (ssh/ansible), मग golden copy शी diff किंवा md5sum lists sort | uniq -c ने compare.

प्र. CI मधे diff प्रत्येक line बदलली दाखवतो पण content सारखा. कारण?

Line endings (CRLF vs LF), trailing spaces किंवा encoding/BOM. cat -A किंवा file ने तपासा; --strip-trailing-cr, -w, किंवा .gitattributes rule.

घरी करून बघा

  1. 10 मित्रांची नावं आणि शहर 'name,city' अशी file मधे लिहा. cut, sort, uniq -c ने प्रत्येक शहरात किती मित्र ते शोधा.
  2. एक config file copy करा, एक line बदला, आणि diff -u ने बदल बघा.

सराव Tasks

या scenario बद्दल

Vidarbha Cotton Mills हा नागपूर मधला वस्त्रोद्योग व्यवसाय आहे. Ganesh Wankhede त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे INR मध्ये मोजले जातात आणि AWS resources ap-south-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 16

सोपं passwd मधून usernames

का: Audits ला user list.

काय करायचं: /etc/passwd चा फक्त सातवा field (login shell) (colon ने वेगळे).

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Numbers sort

का: साधा sort 100 ला 9 आधी ठेवतो.

काय करायचं: amounts.txt numerically sort.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Sort करून duplicates काढा

का: Email list साफ.

काय करायचं: emails.txt sort करा आणि प्रत्येक line एकदाच, एका command मधे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Uppercase text

का: Codes uppercase हवेत.

काय करायचं: codes.txt uppercase करून print, file input redirection ने वाचा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Spaces दाबा

का: अनेक spaces cut तोडतात.

काय करायचं: report.txt मधले repeated spaces एकात, < ने वाचून.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Unified diff

का: Config बदल review.

काय करायचं: nginx.conf.orig आणि nginx.conf मधले फरक unified format मधे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम दोन CSV columns

का: फक्त नावं आणि शहरं पाठवा.

काय करायचं: customers.csv चे columns 2 आणि 3 (comma ने वेगळे).

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Column ने CSV sort

का: Top scorers आधी.

काय करायचं: scores.csv (comma) column 3 ने, numbers, सगळ्यात मोठा आधी sort.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Human sizes sort

का: सगळ्यात मोठे folders.

काय करायचं: du -sh /var/* चा output human-number sort ने मोठा आधी.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Repeats मोजा

का: कोणता IP सगळ्यात जास्त?

काय करायचं: ips.txt मधे प्रत्येक line किती वेळा (आधी sort, मग uniq).

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम फक्त duplicates

का: दुहेरी registrations.

काय करायचं: sorted.txt (आधीच sorted) मधे एकापेक्षा जास्त वेळा येणाऱ्या lines.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Windows CR काढा

का: ^M bash scripts तोडतो.

काय करायचं: setup-crlf.sh मधले सगळे \r काढून setup-lf.sh मधे save.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Files शेजारी जोडा

का: नावं आणि emails दोन files मधे.

काय करायचं: ids.txt आणि phones.txt comma ने शेजारी जोडा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम दोन folders compare

का: Backup जुळला का?

काय करायचं: /etc/haproxy आणि /backup/haproxy मधे कोणत्या files वेगळ्या ते थोडक्यात, recursively.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड दोन lists मधल्या common lines

का: जुन्या आणि नव्या दोन्हीत असलेले servers.

काय करायचं: old.txt आणि new.txt sorted. फक्त दोन्हीत असलेल्या lines.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड शांत binary compare

का: Scripts ना फक्त हो/नाही.

काय करायचं: a.bin आणि b.bin byte by byte शांतपणे compare (फक्त exit code).

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

थोडक्यात सांगायचं तर

  1. cut -d -f fields; -c characters.
  2. sort -n -h -r -k -t -u -V -o.
  3. uniq आधी नेहमी sort; uniq -c मोजतो.
  4. tr stdin मधले characters बदलतो, squeeze (-s) किंवा delete (-d).
  5. paste शेजारी; join key वर; comm sorted sets compare.
  6. diff -u बदल दाखवतो; exit 0 same, 1 वेगळ्या.

उजळणी, तुलना आणि मुलाखत cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

Text toolbox. Raw text पासून उत्तरं. cut columns, sort, uniq, tr. uniq आधी नेहमी sort. Log मधले top 5 IPs.
उजळणी card: Text toolbox · PNG download करा · Card page उघडा
Files compare. नेमकं काय बदललं ते कळतं. diff lines, comm lists, cmp bytes. -u वाचता येणारा patch. Config बदल review.
उजळणी card: Files compare · PNG download करा · Card page उघडा
sort vs uniq. Lines क्रमाने. / शेजारचे repeats काढतो.
तुलना: sort vs uniq · PNG download करा · Card page उघडा
diff vs comm. कोणत्याही दोन files. / दोन sorted lists.
तुलना: diff vs comm · PNG download करा · Card page उघडा
uniq duplicates का चुकवतो?. uniq फक्त शेजारच्या lines. आधी sort, मग uniq. Repeats मोजा.
मुलाखत card: uniq duplicates का चुकवतो? · PNG download करा · Card page उघडा
100 हे 9 आधी का?. साधा sort text compare. -n numbers, -h sizes. सगळ्यात मोठे folders.
मुलाखत card: 100 हे 9 आधी का? · PNG download करा · Card page उघडा
Script ^M ने fail?. Windows line ends (CRLF). tr ने \r काढा. Script fix.
मुलाखत card: Script ^M ने fail? · PNG download करा · Card page उघडा
अनेक spaces ने cut तुटतो?. cut प्रत्येक space मोजतो. आधी squeeze, किंवा awk. ps चा column 2.
मुलाखत card: अनेक spaces ने cut तुटतो? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.