Sed Usage.

Two pretty useful sed commands:

[1] Show a particular line only

[2] Dealing with range of lines:

[3] Prepend Text to a File at the Command Line

  • sed -i ‘1i id,gender,age’ mldataset.csv  (Prepend Text to a File at the Command Line)

[4] Remove blank lines from file.

  • sed ‘/^$/d’ input.txt > output.txt
  • grep -v ‘^$’ input.txt > output.txt

(Both grep and sed use special pattern ^$ that matchs the blank lines. Grep -v option means print all lines except blank line.)

References:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s