sed

टेक्स्ट प्रोसेसिंग

इस्तेमाल

sed -i 's/[old]/[new]/g' [file]

पाठ को पंक्ति-दर-पंक्ति बदलता है, अक्सर s/old/new/ से; जगह पर बदलने वाला -i GNU और BSD में अलग है, और अंत में g न हो तो हर पंक्ति में पहला मेल ही बदलता है।

आम विकल्प

विकल्पअर्थ
s/a/b/gReplace a with b; without the trailing g only the first per line
-iEdit in place. GNU takes -i alone, BSD and macOS need -i ""
-EExtended regex; BSD also accepts -r for GNU compatibility
-nPrint nothing unless a command says to, usually with p
-eAdd another expression to the script
-fRead the script from a file

उदाहरण

sed -i 's/foo/bar/g' file.txt

Replaces every foo in place (GNU).

sed -i '' 's/foo/bar/g' file.txt

The same on macOS, with the empty argument.

sed -n '10,20p' file.txt

Prints only lines 10 to 20.

ये पाइप से जोड़कर चलाने के लिए बने हैं। एक ही कमांड से सब करवाने के बजाय तीन जोड़ना छोटा पड़ता है।

कैसे पढ़ें

  • बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
  • तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
  • विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।

आम सवाल

Q. sed क्या करता है?

पाठ को पंक्ति-दर-पंक्ति बदलता है, अक्सर s/old/new/ से; जगह पर बदलने वाला -i GNU और BSD में अलग है, और अंत में g न हो तो हर पंक्ति में पहला मेल ही बदलता है।

Q. इसे कैसे लिखें?

sed -i 's/[old]/[new]/g' [file] — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।

Q. कितने विकल्प जानने लायक़ हैं?

यहाँ 6 दिए हैं; पूरी सूची man sed में है। यह कमांड टेक्स्ट प्रोसेसिंग में आती है।

मिलती-जुलती कमांड

man पेज: man sed