Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
7Activity
0 of .
Results for:
No results containing your search query
P. 1
SED Command Utilities

SED Command Utilities

Ratings: (0)|Views: 1,319|Likes:
Published by api-19625511

More info:

Published by: api-19625511 on Nov 28, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

SED command utilities
Table of Contents

Purpose..................................................................................................................3 Sed Command Introduction....................................................................................3 Regular expression................................................................................................3 sed options.............................................................................................................4

1. To print the file (emulates \u201ccat\u201d).................................................................... 5 2. To print first 10 lines of a file (emulates \u201chead\u201d)............................................ 5 3. To print the last 10 lines of a file (emulates "tail").......................................... 5 4. To print the set of lines................................................................................... 5 5. To print only lines matches the regular expression (emulates "grep")............ 5 6. To print only lines starts with given \u201cregular expression\u201d............................... 5 7. To print only lines ends with given \u201cregular expression\u201d................................ 5 8. To print only lines which contains exact \u201cregular expression\u201d........................ 6 9. To print only lines which do not matches the regular expression.................... 6 10. To print the line immediately after a regular expression............................... 6 11. To print the section of lines between two given strings................................ 6 12. To print all of file EXCEPT section between 2 regular expressions................ 6 13. To print all only the line number of the regular expression........................... 6 14. Beginning 2nd line, print every 3rd line........................................................ 6 15. Delete the first line and print the same in screen......................................... 6 16. Delete the last line and print the same in the screen.................................... 7 17. Delete the set of lines from a file and print the same in screen.................... 7 18. Delete leading white space (spaces, tab)............................................... . . . . . . 7 19. Delete trailing white space (spaces, tab).............................. . . . . . . . . . . . . . . . . . . . . . . . 7 20. Delete both leading and trailing white spaces.............................................. 7 21. Delete the comments from a file (#) and print the same in screen.............. 7 22. Delete the blank lines................................................................................... 7 23. Create a new file removing the blank lines................................................... 7 24. Delete the lines which contain particular string............................................ 8 25. Delete the particular string in a line and print the rest................................. 8 26. Delete all leading blank lines at the beginning of the file.............................. 8 27. Delete all the trailing blank lines at the end of the file.................................. 8 28. Delete every 3rd line in a given file............................................................. 8 29. Delete consecutive duplicate lines in a file................................................... 8 30. Insert 2 blank spaces at the beginning of each line...................................... 8 31. Insert 2 blank spaces at the end of each line................................................ 8 32. Replace the first instance of string............................................................ . . . 8 33. Replace the last instance of a string............................................................. 9 34. Replace the string from particular block....................................................... 9 35. Replace all the instance of string............................................... . . . . . . . . . . . . . . . . . . 9 36. Replace all the instance of string when certain string occurs........................ 9 37. Replace all the instance of string when certain string not occurs................. 9 38. Replace the set of patterns to single string................................................... 9 39. Reverse the order of lines in a given file....................................................... 9 40. Reverse each character on the line............................................................... 9 41. Reverse the file.............................................................................. . . . . . . . . . . . . . . 9 42. Add commas to numeric strings.................................................................. 10 43. Joint two lines, previous line ending with \u201c/\u201d............................................... 10 44. Upper to Lower............................................................................................ 10 45. Lower to Upper............................................................................................ 10 46. Word Count................................................................................. . . . . . . . . . . . . . . . 10

SED command utilities

47. File Copy..................................................................................................... 10 48. Merge two files............................................................................................ 10 49. Double space a file...................................................................................... 10 50. Displaying File with Line Number................................................................ 11

SED command utilities
Purpose

This document contains some useful features of \u201csed\u201d command. These commands are not very common otherwise but are very helpful in case of the need, dealing with different situations.

This document will definitely be helpful for those who work on UNIX Platform. This document can be a part of HELP document while training on UNIX for ALL specially for the new joinees in an organization.

Sed Command Introduction
\u201csed\u201d is a powerful UNIX command. One can modify text across multiple files and
make changes to files without opening them in an interactive editor.

sed is not suitable as a general purpose editor, and is best used to apply a set of modifications to text, particularly if you're managing more than one file. If you want to run a series of once-only edits, you are better off directly editing a file using vi or Emacs, as using sed will take much longer. But if you need to make systematic changes across multiple files, then sed is your best bet.

The sed utility is a stream editor that reads one or more text files, makes editing changes according to a script of editing commands, and writes the results to standard output. The script is obtained from either the script operand string or a combination of the option-arguments from the -e script and -f script_file options.

The sed utility is a stream editor that reads one or more text files, makes editing changes according to a script of editing commands, and writes the results to standard output. The script is obtained from either the script operand string or a combination of the option-arguments from the -e script and -f script_file options.

Sed is extremely powerful, and you can do things in sed that you can't do in any standard word processor. And because sed is external to the word processor and comes with every Unix system in the world, once you learn sed you'll have a very handy tool in your toolkit, even if you rarely use Unix.

Regular expression

We can use regular expressions to express patterns that we may find in the text. If
you've ever used the '*' character on the shell command line, you've used something
that's similar, but not identical to, regular expressions. Here are the special characters
that you can use in regular expressions:

Character Description

Activity (7)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
rschu68 liked this
Sai Nath liked this
esurinach liked this
nranilkumar liked this
itsmemaggy liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->