{"id":3532,"date":"2014-09-07T07:27:16","date_gmt":"2014-09-06T23:27:16","guid":{"rendered":"http:\/\/rmohan.com\/?p=3532"},"modified":"2014-09-07T11:03:37","modified_gmt":"2014-09-07T03:03:37","slug":"sed-example","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=3532","title":{"rendered":"sed example"},"content":{"rendered":"<p>Text Interval:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># Add a blank line after each line<br \/>\nsed G <\/p>\n<p>  # The original delete all blank lines and add a blank line after each line.<br \/>\n# So that each line of text output later and only a blank line.<br \/>\nsed &#8216;\/ ^ $ \/ d; G&#8217; <\/p>\n<p>  # Add two blank lines after each line<br \/>\nsed &#8216;G; G&#8217; <\/p>\n<p>  # All blank lines generated by the first script to delete (ie remove all the even-numbered lines)<br \/>\nsed &#8216;n; d&#8217; <\/p>\n<p>  # Insert before matching pattern &#8220;regex&#8221; line a blank line<br \/>\nsed &#8216;\/ regex \/ {x; p; x;}&#8217; <\/p>\n<p>  # In the matching pattern &#8220;regex&#8221; insert a blank row after row<br \/>\nsed &#8216;\/ regex \/ G&#8217; <\/p>\n<p>  # Before matching pattern &#8220;regex&#8221; line and insert a blank line after each<br \/>\nsed &#8216;\/ regex \/ {x; p; x; G;}&#8217; <\/p>\n<p>Serial number:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># For each line in the file number (simple left alignment). Here the use of &#8220;tabs&#8221;<br \/>\n# (Tab, see the end of this description of the &#8216;\\ t&#8217; of usage) instead of spaces to align the edges.<br \/>\nsed = filename | sed &#8216;N; s \/ \\ n \/ \\ t \/&#8217; <\/p>\n<p>  # For all lines in the file number (line number in left, right-aligned).<br \/>\nsed = filename | sed &#8216;N; s \/ ^ \/ \/; s \/ * \\ (\\ {6, \\} \\.) \\ n \/ \\ 1 \/&#8217; <\/p>\n<p>  # All lines of the file number, but displays only non-blank line number.<br \/>\nsed &#8216;\/.\/=&#8217; filename | sed &#8216;\/.\/N; s \/ \\ n \/ \/&#8217; <\/p>\n<p>  # Calculate the number of (simulated &#8220;wc -l&#8221;) line<br \/>\nsed -n &#8216;$ =&#8217; <\/p>\n<p>Text conversion and substitution:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># Unix environment: convert DOS newlines (CR \/ LF) to Unix format.<br \/>\nsed &#8216;s \/.$\/\/&#8217; # assumes that all lines with CR \/ LF end<br \/>\nsed &#8216;s \/ ^ M $ \/\/&#8217; # in bash \/ tcsh, and will Ctrl-M to press Ctrl-V<br \/>\n  sed &#8216;s \/ \\ x0D $ \/\/&#8217; # ssed, gsed 3.02.80, and later <\/p>\n<p># Unix environment: convert Unix newlines (LF) to DOS format.<br \/>\nsed &#8220;s \/ $ \/` echo -e \\\\\\ r` \/ &#8220;# used in the ksh command<br \/>\nsed &#8216;s \/ $&#8217; &#8220;\/` echo \\\\\\ r` \/ &#8220;# used in the bash command<br \/>\nsed &#8220;s \/ $ \/` echo \\\\\\ r` \/ &#8220;# used in zsh command<br \/>\nsed &#8216;s \/ $ \/ \\ r \/&#8217; # gsed and later 3.02.80 <\/p>\n<p># DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.<br \/>\nsed &#8220;s \/ $ \/\/&#8221; # 1<br \/>\n  sed -n p # Method 2 <\/p>\n<p>  # DOS ENVIRONMENT: convert DOS newlines (CR \/ LF) to Unix format.<br \/>\n# The following script only UnxUtils sed 4.0.7 and later effective. To identify UnxUtils version<br \/>\n# Sed through its unique &#8220;&#8211;text&#8221; option. You can use the help option (&#8220;&#8211;help&#8221;) see<br \/>\n# Where the presence of a &#8220;&#8211;text&#8221; items used in order to determine whether it is UnxUtils version. Other DOS<br \/>\n  # Sed version of this conversion is not possible. But you can use &#8220;tr&#8221; to achieve this transformation.<br \/>\nsed &#8220;s \/ \\ r \/\/&#8221; infile> outfile # UnxUtils sed v4.0.7 or later<br \/>\ntr -d \\ r <infile> outfile # GNU tr version 1.22 or higher <\/p>\n<p># Each line leading &#8220;whitespace&#8221; (spaces, tabs) Delete<br \/>\n# Make Zhizuo aligned<br \/>\nsed &#8216;s \/ ^ [\\ t] * \/\/&#8217; # see note on &#8216;\\ t&#8217; usage description <\/p>\n<p># Each line trailing &#8220;whitespace&#8221; (spaces, tabs) Delete<br \/>\nsed &#8216;s \/ [\\ t] * $ \/\/&#8217; # see note on &#8216;\\ t&#8217; usage description <\/p>\n<p># Whitespace from each line, remove leading and trailing<br \/>\nsed &#8216;s \/ ^ [\\ t] * \/\/; s \/ [\\ t] * $ \/\/&#8217; <\/p>\n<p>  # Insert five spaces at the beginning of each line (so that the full text moves to the right position 5 characters)<br \/>\nsed &#8216;s \/ ^ \/ \/&#8217; <\/p>\n<p>  # To 79 characters for the width, all the text right-aligned<br \/>\nsed -e: a -e &#8216;s \/ ^ \\ {1,78 \\} $ \/ &#038; \/; ta.&#8217; # 78 characters plus the last one space <\/p>\n<p># To 79 characters for the width, so that all the text centered. In method 1, in order to allow the front of each line of text is centered<br \/>\n# Head and behind are filled with blanks. In method 2, in front of the text is filled only during the middle of the text in<br \/>\n# Spaces, and eventually they will have half the space will be deleted. Also behind each row is not filled spaces.<br \/>\nsed -e: a -e &#8216;s \/ ^ \\ {1,77 \\} $ \/ &#038; \/; ta.&#8217; # 1<br \/>\n  sed -e: a -e &#8216;s \/ ^ \\ {1,77 \\} $ \/ &#038; \/; ta.&#8217; -e &#8216;s \/ \\ (* \\) \\ 1 \/ \\ 1 \/&#8217; # method 2 <\/p>\n<p>  # Find the string on each line &#8220;foo&#8221;, &#8220;foo&#8221; and find the replacement for &#8220;bar&#8221;<br \/>\nsed &#8216;s \/ foo \/ bar \/&#8217; # replaces only the first in each line &#8220;foo&#8221; string<br \/>\nsed &#8216;s \/ foo \/ bar \/ 4&#8217; # replaces only every fourth row &#8220;foo&#8221; string<br \/>\nsed &#8216;s \/ foo \/ bar \/ g&#8217; # each line all &#8220;foo&#8221; are replaced by &#8220;bar&#8221;<br \/>\nsed &#8216;s \/ \\ (. * \\) foo \\ (. * foo \\) \/ \\ 1bar \\ 2 \/&#8217; # replaces the penultimate &#8220;foo&#8221;<br \/>\nsed &#8216;s \/ \\ (. * \\) foo \/ \\ 1bar \/&#8217; # replace the last one &#8220;foo&#8221; <\/p>\n<p>Case # only line string &#8220;baz&#8221; appears in the &#8220;foo&#8221; replaced &#8220;bar&#8221;<br \/>\nsed &#8216;\/ baz \/ s \/ foo \/ bar \/ g&#8217; <\/p>\n<p>  Under # will replace &#8220;foo&#8221; replaced &#8220;bar&#8221;, and only the line string &#8220;baz&#8221; does not appear in the case<br \/>\nsed &#8216;\/ baz \/! s \/ foo \/ bar \/ g&#8217; <\/p>\n<p>  # Whether &#8220;scarlet&#8221; &#8220;ruby&#8221; or &#8220;puce&#8221;, shall be replaced by &#8220;red&#8221;<br \/>\nsed &#8216;s \/ scarlet \/ red \/ g; s \/ ruby ??\/ red \/ g; s \/ puce \/ red \/ g&#8217; # sed are valid for most of<br \/>\ngsed &#8216;s \/ scarlet \\ | ruby ??\\ | puce \/ red \/ g&#8217; # GNU sed only valid <\/p>\n<p># Upside down all the rows, the first row as the last row, and so on (analog &#8220;tac&#8221;).<br \/>\n# For some reason, use the following command HHsed v1.5 will delete blank lines in the file<br \/>\nsed &#8216;! 1 G; h;! $ d&#8217; # method 1<br \/>\n  sed -n &#8216;! 1 G; h; $ p&#8217; # method 2 <\/p>\n<p>  # The line of characters in reverse order, the first word to be the last word, &#8230;&#8230; (analog &#8220;rev&#8221;)<br \/>\nsed &#8216;\/\\n\/!G;s\/\\(.\\)\\(.*\\n\\)\/&#038;\\2\\1\/;\/\/D;s\/.\/\/&#8217; <\/p>\n<p>  # The two lines each connected in a row (like &#8220;paste&#8221;)<br \/>\nsed &#8216;! $ N; s \/ \\ n \/ \/&#8217; <\/p>\n<p>  # If the current line with a backslash &#8220;\\&#8221; end, then the next line and to the current end of the line<br \/>\n# And remove the original trailing backslash<br \/>\nsed -e: a -e &#8216;\/ \\\\ $ \/ N; s \/ \\\\\\ n \/\/; ta&#8217; <\/p>\n<p>  # If the current line begins with an equal sign, the current line and onto the end of a line<br \/>\n# And a single space instead of the original first line of &#8220;=&#8221;<br \/>\nsed -e: a -e &#8216;$ N; s \/ \\ n = \/ \/; ta!&#8217; -e &#8216;P; D&#8217; <\/p>\n<p>  # Add a comma delimited string of numbers, the &#8220;1234567&#8221; to &#8220;1,234,567&#8221;<br \/>\ngsed &#8216;: a; s \/ \\ B [0-9] \\ {3 \\} \\> \/, &#038; \/; ta&#8217; # GNU sed<br \/>\n  sed -e: a -e &#8216;(. * [0-9] \\) s \/ \\ \\ ([0-9] \\ {3 \\} \\) \/ \\ 1, \\ 2 \/; ta&#8217; # other sed <\/p>\n<p>  # Is a number with a decimal point and negative sign of increased comma delimited (GNU sed)<br \/>\ngsed -r &#8216;: a; s \/ (^ | [^ 0-9.]) ([0-9] +) ([0-9] {3}) \/ \\ 1 \\ 2, \\ 3 \/ g; ta &#8216;<\/p>\n<p>  # Add a blank line (5,10,15,20 in the first, and so increase the line after a blank line) after each line 5<br \/>\ngsed &#8216;0 ~ 5G&#8217; # GNU sed only valid<br \/>\nsed &#8216;n; n; n; n; G;&#8217; # other sed <\/p>\n<p>To selectively display a particular row:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># Display the file first 10 lines (analog &#8220;head&#8221; of behavior)<br \/>\nsed 10q <\/p>\n<p>  # Display the file in the first row (analog &#8220;head -1&#8221; command)<br \/>\nsed q <\/p>\n<p>  # Display the last 10 lines of a file (Analog &#8220;tail&#8221;)<br \/>\nsed -e: a -e &#8216;$ q; N; 11, $ D; ba&#8217; <\/p>\n<p>  # Display file last two lines (analog &#8220;tail -2&#8221; command)<br \/>\nsed &#8216;! $ N;! $ D&#8217; <\/p>\n<p>  # Display file last line (analog &#8220;tail -1&#8221;)<br \/>\nsed &#8216;$! d&#8217; # method 1<br \/>\n  sed -n &#8216;$ p&#8217; # method 2 <\/p>\n<p>  # Display file penultimate line<br \/>\nsed -e &#8216;$ {h; d;}!&#8217; -ex # When the file only when one line, enter a blank line<br \/>\nsed -e &#8216;1 {$ q;}&#8217; -e &#8216;$! {h; d;}&#8217; -ex # When the file only when the line displays the line<br \/>\nsed -e &#8216;1 {$ d;}&#8217; -e &#8216;$ {h; d;}!&#8217; -ex # When the file only when the line is not output <\/p>\n<p># Show only rows matching regular expression (analog &#8220;grep&#8221;)<br \/>\nsed -n &#8216;\/ regexp \/ p&#8217; # method 1<br \/>\n  sed &#8216;\/ regexp \/! d&#8217; # method 2 <\/p>\n<p>  # Only shows &#8220;no&#8221; regular expression matching lines (analog &#8220;grep -v&#8221;)<br \/>\nsed -n &#8216;\/ regexp \/! p&#8217; # method 1, corresponds with the previous command<br \/>\nsed &#8216;\/ regexp \/ d&#8217; # method 2, similar syntax <\/p>\n<p># Find &#8220;regexp&#8221; and matching rows displayed on a single line, but does not display the matching lines<br \/>\nsed -n &#8216;\/ regexp \/ {g; 1 p;!}; h&#8217; <\/p>\n<p>  # Find &#8220;regexp&#8221; the next line and matching rows displayed, but does not display the matching lines<br \/>\nsed -n &#8216;\/ regexp \/ {n; p;}&#8217; <\/p>\n<p>  # Display a &#8220;regexp&#8221; line before and after the line, and before the first row plus &#8220;regexp&#8221; the<br \/>\n# Line line number (similar to &#8220;grep -A1 -B1&#8221;)<br \/>\nsed -n -e &#8216;\/ regexp \/ {=; x; 1 p;! g; $ N;! p; D;}&#8217; -e h <\/p>\n<p>  # Display a &#8220;AAA&#8221;, &#8220;BBB&#8221; or &#8220;CCC&#8221; of the row (in any order)<br \/>\nsed &#8216;\/ AAA \/ d;!! \/ BBB \/ d;! \/ CCC \/ d&#8217; # string does not affect the order of the results <\/p>\n<p># Display a &#8220;AAA&#8221;, &#8220;BBB&#8221; and &#8220;CCC&#8221; line (fixed order)<br \/>\nsed &#8216;\/AAA.*BBB.*CCC\/!d&#8217; <\/p>\n<p>  # Display a &#8220;AAA&#8221; &#8220;BBB&#8221; or &#8220;CCC&#8221; line (analog &#8220;egrep&#8221;)<br \/>\nsed -e &#8216;\/ AAA \/ b&#8217; -e &#8216;\/ BBB \/ b&#8217; -e &#8216;\/ CCC \/ b&#8217; -ed # majority sed<br \/>\n  gsed &#8216;\/ AAA \\ | BBB \\ |! CCC \/ d&#8217; # GNU sed on effective <\/p>\n<p>Paragraph (separated by a blank line between paragraphs) # display a &#8220;AAA&#8221; of<br \/>\n# HHsed v1.5 must be in the &#8220;x;&#8221; after joining the &#8220;G;&#8221;, the next three scripts are so<br \/>\nsed -e &#8216;\/.\/{H;$!d;}&#8217; -e &#8216;x; \/ AAA \/ d;!&#8217; <\/p>\n<p>  Paragraph (in any order) # display a &#8220;AAA&#8221; &#8220;BBB&#8221; and &#8220;CCC&#8221; three strings<br \/>\nsed -e &#8216;\/.\/{H;$!d;}&#8217; -e &#8216;x; \/ AAA \/ d;! \/ BBB \/ d;!! \/ CCC \/ d&#8217; <\/p>\n<p>  # Display a &#8220;AAA&#8221;, &#8220;BBB&#8221;, &#8220;CCC&#8221; to any one of the three passages of the string (in any order)<br \/>\nsed -e &#8216;\/.\/{H;$!d;}&#8217; -e &#8216;x; \/ AAA \/ b&#8217; -e &#8216;\/ BBB \/ b&#8217; -e &#8216;\/ CCC \/ b&#8217; -ed<br \/>\n  gsed &#8216;\/.\/{H;$!d;};x;\/AAA\\|BBB\\|CCC\/b;d&#8217; # GNU sed only valid <\/p>\n<p>Line # Display contains 65 or more characters<br \/>\nsed -n &#8216;\/^.\\{65\\}\/p&#8217; <\/p>\n<p>  # Display line contains 65 characters or less<br \/>\nsed -n &#8216;\/^.\\{65\\}\/!p&#8217; # method 1, corresponds with the above script<br \/>\nsed &#8216;\/^.\\{65\\}\/d&#8217; # method 2, a little more simple way <\/p>\n<p># Display some of the text &#8211; from the row that contains the regular expression to the last line ends<br \/>\nsed -n &#8216;\/ regexp \/, $ p&#8217; <\/p>\n<p>  # Display some of the text &#8211; the specified line number range (from 8 to 12 lines, with 8 and 12 lines)<br \/>\nsed -n &#8216;8,12p&#8217; # 1<br \/>\n  sed &#8216;8,12! d&#8217; # method 2 <\/p>\n<p>  # Display line 52<br \/>\nsed -n &#8217;52p&#8217; # method 1<br \/>\n  sed &#8217;52! d &#8216;# method 2<br \/>\n  sed &#8217;52q; d&#8217; # method 3, more efficient when dealing with large files <\/p>\n<p># From the beginning of the third line, the line is displayed once every 7<br \/>\ngsed -n &#8216;3 ~ 7p&#8217; # GNU sed only valid<br \/>\nsed -n &#8216;3, $ {p; n; n; n; n; n; n;}&#8217; # other sed <\/p>\n<p>  # Display between two regular text expression (including)<br \/>\nsed -n &#8216;\/ Iowa \/, \/ Montana \/ p&#8217; # case sensitive manner <\/p>\n<p>  Selectively remove specific lines:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># Display throughout the document, in addition to the content between two regular expressions<br \/>\nsed &#8216;\/ Iowa \/, \/ Montana \/ d&#8217; <\/p>\n<p>  # Delete duplicate files in adjacent rows (analog &#8220;uniq&#8221;)<br \/>\n# Retain only duplicate rows in the first row, the other rows deleted<br \/>\nsed &#8216;$ N;! \/^\\(.*\\)\\n\\1$\/!P; D&#8217; <\/p>\n<p>  # Delete duplicate lines in the file, regardless of whether the neighbor. Note hold space can support cache<br \/>\n# Size, or use GNU sed.<br \/>\nsed -n &#8216;G; s \/ \\ n \/ &#038;&#038; \/;. \/ ^ \\ ([- ~] * \\ n \\) * \\ n \\ 1 \/ d; s \/ \\ n \/\/; h; P&#8217; <\/p>\n<p>  # Delete all lines (analog &#8220;uniq -d&#8221;) except duplicate rows<br \/>\nsed &#8216;! $ N; s \/ ^ \\ \\ n \\ 1 $ \/ \\ 1 \/ (* \\.); t; D&#8217; <\/p>\n<p>  # Delete files in the beginning of the 10 lines<br \/>\nsed &#8216;1,10d&#8217; <\/p>\n<p>  # Delete the last line in the file<br \/>\nsed &#8216;$ d&#8217; <\/p>\n<p>  # Delete files in the last two lines<br \/>\nsed &#8216;N; $ P;! $ D;! $ d&#8217; <\/p>\n<p>  # Delete files in the last 10 lines<br \/>\nsed -e: a -e &#8216;$ d; N; 2,10ba&#8217; -e &#8216;P; D&#8217; # 1<br \/>\n  sed -n -e: a -e &#8216;1,10 {P; N; D;}; N; ba!&#8217; # method 2 <\/p>\n<p>  # Delete multiple rows 8<br \/>\ngsed &#8216;0 ~ 8d&#8217; # GNU sed only valid<br \/>\nsed &#8216;n; n; n; n; n; n; n; d;&#8217; # other sed <\/p>\n<p>  # Delete the rows matching style<br \/>\nsed &#8216;\/ pattern \/ d&#8217; # delete the row containing the pattern is. Of course pattern<br \/>\n                                         # Can be replaced with any valid regular expression <\/p>\n<p># Delete files all blank lines (with &#8220;grep &#8216;.'&#8221; The same effect)<br \/>\nsed &#8216;\/ ^ $ \/ d&#8217; # method 1<br \/>\n  sed &#8216;\/.\/!d&#8217; # method 2 <\/p>\n<p>  # Keep only the first line of multiple adjacent blank lines. And delete files at the top and tail of blank lines.<br \/>\n# (Analog &#8220;cat -s&#8221;)<br \/>\nsed &#8216;\/.\/,\/^$\/!d&#8217; # method 1, the empty rows to delete files at the top, allowing the tail to keep a blank line<br \/>\nsed &#8216;\/ ^ $ \/ N; \/ \\ n $ \/ D&#8217; # method 2, allows the top to retain a blank line, the tail does not leave blank lines <\/p>\n<p># Only the first two lines keep multiple adjacent blank lines.<br \/>\nsed &#8216;\/ ^ $ \/ N; \/ \\ n $ \/ N; \/\/ D&#8217; <\/p>\n<p>  # Delete all blank lines at top of file<br \/>\nsed &#8216;\/.\/,$!d&#8217; <\/p>\n<p>  # Delete all files trailing blank lines<br \/>\nsed -e: a -e &#8216;\/ ^ \\ n * $ \/ {$ d; N; ba&#8217; -e &#8216;}&#8217; # sed valid for all<br \/>\nsed -e: a -e &#8216;\/ ^ \\ n * $ \/ N; \/ \\ n $ \/ ba&#8217; # above, but only for gsed 3.02 * valid. <\/p>\n<p># Delete the last line of each paragraph<br \/>\nsed -n &#8216;\/^$\/{p;h;};\/.\/{x;\/.\/p;}&#8217; <\/p>\n<p>Special applications:<br \/>\n&#8212;&#8212;&#8211; <\/p>\n<p># Remove manual page (man page) in nroff mark. In the Unix System V or bash shell so<br \/>\nMay need to add -e option # use &#8216;echo&#8217; command.<br \/>\nsed &#8220;s \/ .`echo \\\\\\ b` \/\/ g&#8221; # outer pair of parentheses is required (Unix environment)<br \/>\nsed &#8216;s \/.^ H \/\/ g&#8217; # in bash or tcsh, press Ctrl-V and then press Ctrl-H<br \/>\n  sed &#8216;s \/. \\ x08 \/\/ g&#8217; # sed 1.5, GNU sed, ssed uses hexadecimal representation <\/p>\n<p># Extract newsgroup or e-mail message header<br \/>\nsed &#8216;\/ ^ $ \/ q&#8217; # delete all the contents of the first row after row of empty <\/p>\n<p># Extract the body of the news group or e-mail the<br \/>\nsed &#8216;1, \/ ^ $ \/ d&#8217; # delete all content blank lines before the first line of <\/p>\n<p># Extract the &#8220;Subject&#8221; (the title bar field) from the message header, and remove the beginning of the &#8220;Subject:&#8221; words<br \/>\nsed &#8216;! \/ ^ Subject: * \/ d; s \/\/\/; q&#8217; <\/p>\n<p>  # Get the return address from the message header<br \/>\nsed &#8216;\/ ^ Reply-To: \/ q; \/ ^ From: \/ h; \/.\/d;g;q&#8217; <\/p>\n<p>  # Get the e-mail address. On the basis of that line messages generated by a script on the head of a further non-email<br \/>\nPart # address shave. (See a script)<br \/>\nsed &#8216;s \/ * \/\/; s \/>.*\/\/; s \/.* (*.) [: <] * \/\/' \n\n  # At the beginning of each line with a sharp brackets and spaces (reference information) \nsed 's \/ ^ \/> \/&#8217; <\/p>\n<p>  # At the beginning of each line angle brackets and spaces removed (dereference)<br \/>\nsed &#8216;s \/ ^> \/\/&#8217; <\/p>\n<p>  # Remove most HTML tags (including interbank label)<br \/>\nsed -e: a -e &#8216;s \/ <[^>] *> \/\/ g; \/ <\/ N; \/\/ ba' \n\n  # Will be divided into multiple volumes decode uuencode files. Remove the file header information, leaving only uuencode coding part. \n# File must be passed to sed in a specific order. The first version of the script below can be entered directly in the command line; \n# The second version can be placed in a shell script with execute permissions. (By Rahul Dhesi of a \n# Modified from a script. ) \nsed '\/ ^ end \/, \/ ^ begin \/ d' file1 file2 ... fileX |. uudecode # vers 1 \n  sed '\/ ^ end \/, \/ ^ begin \/ d' \"$ @\" |. uudecode # vers 2 \n\n  # The file is sorted in alphabetical order paragraphs. Between paragraphs to (one or more lines) separated by a blank line. GNU sed use \n# Character \"\\ v\" to represent the vertical tab, where it is used as a placeholder line breaks - of course you can \n# Unused by other characters in the file instead. \nsed '\/.\/{H;d;};x;s\/\\n\/={NL}=\/g' file | sort | sed '1s \/ = {NL} = \/\/; s \/ = {NL} = \/ \\ n \/ g '\n  gsed '\/.\/{H;d};x;y\/\\n\/\\v\/' file | sort | sed '1s \/ \\ v \/\/; y \/ \\ v \/ \\ n \/' \n\n  .ZIP File # compress each separately .TXT file, delete the original files after compression and compressed \n# Named the same as the original name (but different extensions). (DOS environment: \"dir \/ b\" \n# Display the file name without the path). \nechoecho off> zipup.bat<br \/>\n  dir \/ b * .txt | sed &#8220;s \/ ^ \\ \\ TXT \/ pkzip -mo \\ 1 \\ 1.TXT \/ (* \\.).&#8221; >> zipup.bat <\/p>\n<p>Use SED: Sed takes one or more editing commands, and each line of input in order to apply these commands.<br \/>\n  When reading the first line of the input after, sed their applications all command, and outputs the result. Then read the second<br \/>\n  Line input, their applications all command &#8230;&#8230; and repeat the process. Sed on an example from the standard input device<br \/>\n  Equipment (ie, command interpreter, usually in the form of piped) to obtain input. Or give a command line<br \/>\n  When a file name as an argument, the files become sed to replace the standard input device input. sed the output will be<br \/>\n  Sent to standard output (monitor). As such: <\/p>\n<p>cat filename | sed &#8217;10q&#8217; # use piped input<br \/>\nsed &#8217;10q&#8217; filename # same effect, but does not use the pipe input<br \/>\nsed &#8217;10q&#8217; filename> newfile # The output transfer (redirect) to disk <\/p>\n<p>  To understand the instructions for use sed command, including how to use via a script file (rather than from the command line) these life<br \/>\n  Order, please refer to &#8220;sed &#038; awk&#8221; second edition, author Dale Dougherty and Arnold Robbins<br \/>\n(O&#8217;Reilly, 1997; http: \/\/www.ora.com), &#8220;UNIX Text Processing&#8221;, author<br \/>\nDale Dougherty and Tim O&#8217;Reilly (Hayden Books, 1987), or write to teach Mike Arst<br \/>\n  Cheng &#8211; the name of the archive is the &#8220;U-SEDIT2.ZIP&#8221; (on many sites can find it). To explore sed<br \/>\nPotential, it must be on the &#8220;regular expression&#8221; sufficient understanding. Information on regular expressions can be seen<br \/>\n  &#8220;Mastering Regular Expressions&#8221; author Jeffrey Friedl (O&#8217;reilly 1997).<br \/>\nUnix systems provide manual page (&#8220;man&#8221;) would also be helpful (try these commands<br \/>\n&#8220;Man sed&#8221;, &#8220;man regexp&#8221;, or see &#8220;man ed&#8221; in the section on regular expressions), but<br \/>\n  Comparative information booklet provided &#8220;abstract&#8221; &#8211; this is it&#8217;s always been criticized. However, it should not have<br \/>\n  Is used to teach beginners how to use regular expressions sed or materials, but only for those who are familiar with these tools<br \/>\n  Some texts provide references. <\/p>\n<p>  Bracket syntax: The preceding examples sed command basically use single quotation marks (&#8216;&#8230;&#8217;) instead of double quotes<br \/>\n  (&#8220;&#8230;&#8221;) This is because sed is typically used on Unix platforms. Under the single quotes, Unix&#8217;s shell (command<br \/>\n  Interpreter) does the dollar sign ($) and post quotes (`&#8230;`) be interpreted and executed. And in double quotes under<br \/>\n  Dollar sign will be expanded to the value of a variable or parameter, after the command is executed in quotation marks and replace output results<br \/>\n  After the quotes content. Need to use an exclamation point when its front in &#8220;csh&#8221; shell and derivatives of the (!)<br \/>\n  Escaped with a backslash plus side (like this:! \\) To ensure that the above example can be used in normal operation<br \/>\n  (Including the use of single quotation marks under circumstances). DOS version of Sed then always use double quotes (&#8220;&#8230;&#8221;) rather than<br \/>\n  Quotes to enclose command. <\/p>\n<p>&#8216;\\ t&#8217; Usage: For clarity in documentation, we use the script &#8216;\\ t&#8217; to indicate a tab<br \/>\n  Character. However, most versions of sed do not recognize the &#8216;\\ t&#8217; shorthand, so when the command line is<br \/>\n  When the script Input tabs, you should press the TAB key to enter tabs instead of typing &#8216;\\ t&#8217;. The following work<br \/>\n  With software support &#8216;\\ t&#8217; character as a regular expression to represent tabs: awk, perl, HHsed,<br \/>\nsedmod and GNU sed v3.02.80. <\/p>\n<p>  Different versions of the SED: sed between different versions will be some differences, imagine in syntax between them<br \/>\n  Vary. Specifically, the majority of them do not support the use of labels in the edit command (: name) or sub-<br \/>\n  Branch commands (b, t), except those at the end. This document we try to use a high portability<br \/>\n  Syntax, so most versions of sed users can use these scripts. However, the version of GNU sed allow<br \/>\n  With a more concise syntax. Imagine the feeling when readers see a very long time the command: <\/p>\n<p>    sed -e &#8216;\/ AAA \/ b&#8217; -e &#8216;\/ BBB \/ b&#8217; -e &#8216;\/ CCC \/ b&#8217; -e d <\/p>\n<p>The good news is GNU sed command enables more compact: <\/p>\n<p>    sed &#8216;\/ AAA \/ b; \/ BBB \/ b; \/ CCC \/ b; d&#8217; # even be written<br \/>\n    sed &#8216;\/ AAA \\ | BBB \\ | CCC \/ b; d&#8217; <\/p>\n<p>Also, please note that although many versions of sed accept as &#8220;\/ one \/ s \/ RE1 \/ RE2 \/&#8221; this before &#8216;s&#8217; with an empty<br \/>\n  Georgia&#8217;s commands, but some of these versions do not accept this command: &#8220;\/ one \/ s \/ RE1 \/ RE2 \/!&#8221;. Then<br \/>\n  Just need to get rid of the middle of the space on the line. <\/p>\n<p>  Speed ??optimization: When for some reason (for example, a large input file, the processor is too slow, or hard disk) the need to improve<br \/>\n  When the command execution speed, consider replacing the command (&#8220;s \/&#8230;\/&#8230;\/&#8221;) preceded by address expressions<br \/>\n  Increase speed. For example: <\/p>\n<p>    sed &#8216;s \/ foo \/ bar \/ g&#8217; filename # standard replace command<br \/>\n    sed &#8216;\/ foo \/ s \/ foo \/ bar \/ g&#8217; filename # Faster<br \/>\n    sed &#8216;\/ foo \/ s \/\/ bar \/ g&#8217; filename # shorthand <\/p>\n<p>  When you need to display only the front part of the file or delete the contents of the back when needed, you can use the &#8220;q&#8221; in the script<br \/>\nCommand (Exit command). When dealing with large files, this will save a lot of time. As such: <\/p>\n<p>    sed -n &#8217;45, 50p &#8216;filename # Showing 45-50 OK<br \/>\n    sed -n &#8217;51q; 45,50p&#8217; filename # same, but faster <\/p>\n<p>  If you have another one-line script would like to share with you or you find in this document the wrong place, please power<br \/>\n  E-mail to the author of this document (Eric Pement). Please remember to provide the message sed version you are using,<br \/>\n  Operating system and proper description of the sed running of the problem. One-line script referred to herein refers to the command line length<br \/>\n  Degrees in 65 characters or less 65 Annotation [1] sed script. Various scripts in this document is made as listed below<br \/>\n  Who wrote or provide:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Text Interval: &#8212;&#8212;&#8211; <\/p>\n<p># Add a blank line after each line sed G <\/p>\n<p> # The original delete all blank lines and add a blank line after each line. # So that each line of text output later and only a blank line. sed &#8216;\/ ^ $ \/ d; G&#8217; <\/p>\n<p> # [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3532"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3532"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3532\/revisions"}],"predecessor-version":[{"id":3534,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/3532\/revisions\/3534"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}