background preloader

Social Media

Facebook Twitter

Get started. Tumblr. Twitter. Facebook. Sed tip: Remove / Delete All Leading Blank Spaces / Tabs ( whitespace ) From Each Line. The sed (Stream Editor) is very powerful tool. Each line of input is copied into a pattern space. You can run editing commands on each input line to delete or change the input. For example, delete lines containing word DVD, enter: cat input.txt | sed '/DVD/d' To Print the lines between each pair of words pen and pencil, inclusive, enter: $ cat input.txt sed -e '/^PEN/,/^PENCIL/p' To remove all blank lines, enter: $ cat /etc/rssh.conf | sed '/^$/d' > /tmp/output.file sed is very handy tool for editing and deleting unwanted stuff. This is a test To remove all whitespace (including tabs) from left to first word, enter: echo " This is a test" | sed -e 's/^[ \t]*//' Output: Where, s/ : Substitute command ~ replacement for pattern (^[ \t]*) on each addressed line^[ \t]* : Search pattern ( ^ - start of the line; [ \t]* match one or more blank spaces including tab)// : Replace (delete) all matched pattern Following sample script reads some data from text file and generate a formatted output.

. #!