← Back to Bash Course | Chapter 11: Process Management | Lesson 11 of 12

wc कमांड

wc एक counter जैसा है जो आपको बताता है कि किसी text में कितनी lines, words या letters हैं। यह एक chain के आखिर में देखने के लिए handy है कि कितना through आया।

In this page:

  1. wc
Syntax
bash
wc [-l | -w | -c] file_name

wc

wc अपने input में lines (-l), words (-w), और characters/bytes (-c) count करता है। इसे अक्सर एक pipeline के आखिर में रखा जाता है यह summarize करने के लिए कि previous filtering steps से कितना data through आया।

बिना किसी flags के इसे run करना तीनों counts साथ में print करता है।

Note: command | wc -l यह count करने का standard idiom है कि एक command ने कितनी lines produce की।

उदाहरण: wc

bash
#!/bin/bash
printf "one\ntwo\nthree\n" > words.txt

echo "Lines: $(wc -l < words.txt)"
echo "Words: $(wc -w < words.txt)"
echo "Characters: $(wc -c < words.txt)"
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. #}
आम गलतियां
  1. wc -l उपयोग करना और यह उम्मीद करना कि trailing newline के बिना last line count होगी।
  2. wc -l file output को सिर्फ एक number के रूप में पढ़ना, जब इसमें file name भी शामिल होता है।
  3. -c (bytes) और -m (characters) को confuse करना।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.