Tuesday, June 15, 2010

SED Linux command

SED Linux Command



sed stands for "stream editor".

SYNOPSIS

% sed [-an] command [file ...]
% sed [-an] [-e command] [-f command_file] [file ...]

DESCRIPTION

sed can be used to filter text files. The pattern to match is typically included between a pair of slashes // and quoted.
For EXAMPLE, to print lines containing the string "1024", you may use:

cat filename | sed -n '/1024/p'

Here, sed filters the output from the cat command. The option "-n" tells sed to block all the incoming lines but those explicitly matching the expression. The sed action on a match is "p"= print.
Here is another EXAMPLE, this time for deleting selected lines:

cat filename | sed '/.*o$/d' > new_file

In this EXAMPLE, lines ending with an "o" will be deleted. It uses a regular expression for matching any string followed by an "o" and the end of the line. The output (i.e., all lines but those ending with "o") is directed to new_file.

To search and replace, use the sed 's' action, which comes in front of two expressions:

cat filename | sed 's/string_old/string_new/' > newfile

1 comment:

  1. Hi Vikas,

    SED Linux command being contrived to exist for many projects simply so it can be run will be the first to hit the wall, but those projects where the functions to make existing transactions cheaper in real world applications will find the elusive real-world demand.
    The /boot/ directory contains static files required to boot the system, such as the Linux kernel, boot loader configuration files. These files are essential for the system to boot properly.

    Is there a way I can make partitions for Linux on my 2 TB external HDD and be able to boot into linux from my HDD?
    Thank you very much and will look for more postings from you.

    Merci Beaucoup,
    Kevin

    ReplyDelete