Sed-Delete one or more lines from a file
Syntax: C code sed '{[/] <n> | <string> | <regex> [/]} d' <fileName> sed' {[/] <adr1> [, <adr2>] [/] D' <fileName> /... /= delimitersn = line numberstring = string found in lineregex = regular expression corresponding to the searched patternaddr = address of a line (number or pattern) d = delete Examples Remove the 3rd line: C code sed '3d 'fileName.txt Remove the line containing the string "awk": C code sed'/awk/d' fi Lename.txt Remove the last line: C code sed '$ d' filename.txt Remove all empty lines: C code sed'/^ $/d 'filename.txt sed '/./! D 'filename.txt Remove the line matching by a regular expression (by eliminating one containing digital characters, at least 1 digit, located at the end of the line ): C code sed '/[0-9/] [0-9] * $/d' filename.txt Remove the interval between lines 7 and 9: C code sed '7, 9d 'filename.txt The same operation as abve but replacing the address with parameters: C code sed '/-Start/,/-End/d' filename.txt The above examp Les are only changed at the display of the file (stdout1 = screen ). for permanent changes to the old versions (<4) use a temporary file for GNU sed using the "-I [suffix]": C code sed-I ". bak "'3d 'filename.txt Task: Remove blank lines using sedType the following command: C code $ sed'/^ $/d' input.txt> output.txt Task: remove blank lines using grepC code $ grep-v '^ $ 'input.txt> output.txt Both grep and se D use special pattern ^ $ that matchs the blank lines. grep-v option means print all lines except T blank line. let us say directory/home/me/data /*. txt has all text file. use following for loop (shell script) to remove all blank lines from all files stored in/home/me/data directory: C code #! /Bin/sh files = "/home/me/data /*. txt "for I in $ files do sed '/^ $/d' $ I> $ I. out mv $ I. out $ I done Updated for accuracy.