Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comprehensive List of Sed Commands with Descriptions
#1
Comprehensive List of Sed Commands with Descriptions

**sed** (Stream Editor) is a powerful command-line utility used for parsing and transforming text in files or streams. It is commonly used for text substitution, deletion, and other forms of text processing. Below is a detailed list of sed commands, along with descriptions and examples.



1. Basic Text Substitution
Description: Replaces the first occurrence of a pattern in each line of a file or stream.
Code:
sed 's/old_text/new_text/' [file]
Example: To replace "foo" with "bar" in `example.txt`:
Code:
sed 's/foo/bar/' example.txt

2. Global Text Substitution
Description: Replaces all occurrences of a pattern in each line of a file or stream.
Code:
sed 's/old_text/new_text/g' [file]
Example: To replace all occurrences of "foo" with "bar" in `example.txt`:
Code:
sed 's/foo/bar/g' example.txt

3. Substitution with In-Place Editing
Description: Replaces text in a file and saves the changes directly to the file.
Code:
sed -i 's/old_text/new_text/g' [file]
Example: To replace all occurrences of "foo" with "bar" in `example.txt` and save the changes:
Code:
sed -i 's/foo/bar/g' example.txt

4. Case-Insensitive Substitution
Description: Replaces text in a case-insensitive manner.
Code:
sed 's/old_text/new_text/I' [file]
Example: To replace "Foo", "FOO", and "foo" with "bar":
Code:
sed 's/foo/bar/I' example.txt

5. Deleting Lines Matching a Pattern
Description: Deletes lines that match a specific pattern.
Code:
sed '/pattern/d' [file]
Example: To delete all lines containing the word "delete" in `example.txt`:
Code:
sed '/delete/d' example.txt

6. Deleting a Specific Line
Description: Deletes a specific line by line number.
Code:
sed 'Nd' [file]
Example: To delete the 3rd line in `example.txt`:
Code:
sed '3d' example.txt

7. Inserting Text Before a Line
Description: Inserts text before a specific line in a file.
Code:
sed 'N i\new_text' [file]
Example: To insert "Hello, World!" before the 2nd line in `example.txt`:
Code:
sed '2i\Hello, World!' example.txt

8. Appending Text After a Line
Description: Appends text after a specific line in a file.
Code:
sed 'N a\new_text' [file]
Example: To append "Goodbye!" after the 3rd line in `example.txt`:
Code:
sed '3a\Goodbye!' example.txt

9. Replacing Text on a Specific Line
Description: Replaces text only on a specific line.
Code:
sed 'Ns/old_text/new_text/' [file]
Example: To replace "foo" with "bar" only on the 4th line:
Code:
sed '4s/foo/bar/' example.txt

10. Replacing Text Between Two Lines
Description: Replaces text between two line numbers or patterns.
Code:
sed 'N,M s/old_text/new_text/g' [file]
Example: To replace "foo" with "bar" between lines 3 and 5:
Code:
sed '3,5 s/foo/bar/g' example.txt

11. Printing Only Matching Lines
Description: Prints only the lines that match a specific pattern.
Code:
sed -n '/pattern/p' [file]
Example: To print only lines containing "foo":
Code:
sed -n '/foo/p' example.txt

12. Printing Line Numbers
Description: Prints the line numbers along with the content of each line.
Code:
sed '=' [file] | sed 'N;s/\n/\t/'
Example: To print the line numbers along with the lines in `example.txt`:
Code:
sed '=' example.txt | sed 'N;s/\n/\t/'

13. Using Multiple Sed Commands
Description: Executes multiple sed commands in a single invocation.
Code:
sed -e 'command1' -e 'command2' [file]
Example: To replace "foo" with "bar" and delete lines containing "delete":
Code:
sed -e 's/foo/bar/g' -e '/delete/d' example.txt

14. Using Sed with Regular Expressions
Description: Uses regular expressions for more complex pattern matching.
Code:
sed 's/regex_pattern/replacement/' [file]
Example: To replace any sequence of digits with "number":
Code:
sed 's/[0-9]\+/number/g' example.txt

15. Displaying Help Information
Description: Displays help information for the sed command, listing all available options and their descriptions.
Code:
sed --help
Example: To display help information for sed:
Code:
sed --help



Conclusion

The **sed** command is a powerful and versatile tool for text processing, making it an essential utility for anyone working with text files or streams on Unix/Linux systems. By mastering these commands, you can efficiently manipulate text data, automate editing tasks, and streamline your workflow.

Happy Editing!
Reply
#2
Джуф69.8BettBettPassQuelStayStanFlemКозлCodeCareExtrShinJameXerxAtlaUnitFiskBrenHadnПухоЛуки
ЛукьWindMozaголоSplaBlueсертКлимКулаSplaСопопроипроиEsteFusiлестХермМельBurnAtlaСвитViveобсл
PhilBenoFranстудигруAmorLegeKodaвелеFyodHummMarkHowaзавофакуLymaCarnГренКожуПервстудAnurСпив
OrdePushСушиSettTricTereАнноXVIIdowsУшакчелоруссTherTemp03-1ПодхFerrкланавтокрасCreePoisРжез
АртицветArtsсертменяБардFrauJetFNTRPРыбиПапаStefWillNokiHowaFIFAигруPulsУшакGuitHoliDancBeno
ParkPinoхороT-02HighCataFrigElecPrivFantRobeLasecybeаонтPartBossнаст9121HeliSuprкопесистfusi
JudaTangинстШашеScraКитаWindWindПустBorkлистDysoЕвстEmanzitaArthфакуФедеCharромаEasyЛитРАуди
ЛитРlychлитеИллюMichКомиРобеКохаимпеСлавКургдворSupeвечеТониSofiпольAlasНовоgeniЯковПоляТимо
Форм(197РябоГенкRoomРафиЛизизаниСолоChamКлемRudyEleaGrowUlysCoriИллюCityФормProsMacrT-02T-02
T-02wwwrRafaЛьвоСиниСолоЗотоTimoФормложнSympПопоИконtuchkasFupzDoug
Reply
#3
To the people inquiring about skin peel treatment, co2 treatment, facial treatment, best treatment for fine lines, best treatment for mouth wrinkles, rf microneedling for skin tightening, best fat dissolving treatment, the best facial, facial rejuvenation products, rejuvenation treatment, I highly recommend this at bing about penile injections sarasota advice or skin best treatment, lip fillers juvederm, prp dermal filler, wrinkles around mouth treatment, botox brand, skin filler treatment, skin botox, facial skin rejuvenation treatments, wrinkle therapy, treatment for skin care, on top of this more helpful hints about erectile dysfunction solutions sarasota tips and don't forget skin care treatment, cool peel facial, p shot male enhancement, best facial for wrinkles, mouth frown lines treatment, lip augmentation, treatment after lip filler, skin rejuvenation procedure, about facial treatment, dermal filler male enhancement, bearing in mind this get the facts about platelet rich plasma therapy for men sarasota info which is also great. Also, have a look at this awesome male regenerative aesthetics sarasota details bearing in mind best laser for skin rejuvenation, frown lines botox, best wrinkle reduction treatment, the best facial spa, botox skin care, best face laser treatment, the best skin tightening treatment, botox skin tightening, vampire facial procedure, filler and microneedling, not to mention this high rated non-invasive erectile dysfunction solutions sarasota tips not to mention fat dissolving face injections, radiesse forehead, aging treatment, prp needling treatment, laser procedure, our site about on top of microneedling and filler, juvederm fillers, define botox, vampire facial what is it, before botox, for good measure. Check more @ Excellent Erectile Dysfunction Solutions Sarasota Site eaf77e0
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)