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

cut कमांड

cut text की एक table से एक column snip out करने के लिए scissors उपयोग करने जैसा है। आप इसे बताते हैं कि columns को क्या separate करता है और आपको कौन सा column number चाहिए।

In this page:

  1. cut
Syntax
bash
cut -d'delimiter' -f field_number
cut -c start-end

cut

cut input की हर line से specific columns या character ranges extract करता है, delimiter set करने के लिए -d और fields चुनने के लिए -f उपयोग करते हुए।

जब आपको सिर्फ एक या दो fields निकालनी हों तो यह awk का एक lighter-weight alternative है। cut -c delimiter-separated fields के बजाय character position से extract करता है।

Note: CSV-style lines से second comma-separated field extract करने के लिए cut -d, -f2 उपयोग करें।

उदाहरण: cut

bash
#!/bin/bash
echo "alice,30,engineer" | cut -d, -f1
echo "alice,30,engineer" | cut -d, -f2,3
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. cut -d को एक multi-character delimiter के साथ उपयोग करना, जो allowed नहीं है।
  2. Multiple spaces वाले space separated data पर -f fields उपयोग करना, जब cut हर space को एक delimiter मानता है।
  3. Delimiter भूल जाना, इसलिए default tab उपयोग होता है।

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.