uniq कमांड
uniq एक teacher जैसा है जो एक list में साथ-साथ बैठे repeated names को cross out करता है। यह सिर्फ उन repeats को spot करता है जो एक-दूसरे के बगल में होते हैं, इसलिए आप पहले sort करते हैं।
In this page:
Syntax
sort file_name | uniq [-c]
uniq
uniq sorted input से consecutive duplicate lines हटाता है, इसलिए यह almost हमेशा एक pipeline में sort के बाद उपयोग होता है। -c हर line के पहले यह count prefix करता है कि यह कितनी बार occur हुई।
पहले sort किए बिना, uniq उन duplicates को miss कर देगा जो adjacent नहीं हैं।
Warning:
uniq सिर्फ *adjacent* duplicate lines हटाता है — अगर duplicates एक-दूसरे के बगल में न हों तो हमेशा पहले sort करें।उदाहरण: uniq
#!/bin/bash
printf "apple\nbanana\napple\napple\ncherry\n" | sort | uniq
echo "---"
printf "apple\nbanana\napple\napple\ncherry\n" | sort | uniq -c
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
sortके बिनाuniqउपयोग करना, क्योंकि यह सिर्फ adjacent duplicates हटाता है।- Counts चाहिए होने पर
-cभूल जाना। - यह उम्मीद करना कि
uniqबिना-iके case ignore करेगा।
🔒
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: