Posts Tagged With: sed

Add Line Numbers

Tagged with: , , , , , ,

Use this command to add line numbers to a text file…


sed = filename.txt | sed 'N;s/\n/\t/' > filename_number.txt
3 Comments »

Delete Leading Whitespace Using Sed

Tagged with: , , , , ,

Delete leading whitespace (spaces/tabs/etc) from beginning of each line. Same as yesterday’s command – but using sed


cat file.txt | sed -e 's,^ *,,'

Credit: Vivin

No Comments »

Sed Regular Expression Range

Tagged with: , , , , , ,

Print the contents of a file from a given regular expression to another


sed -n '/start/,/end/ p' file

This will print the contents of the ‘file’ from the line that matches /start/ until the line that matches /end/

No Comments »

View some lines in a file

Tagged with: , , , ,

View from 1th to 5th line


sed -n '1,5p;5q' example.txt
No Comments »

Remove Empty Characters at End of Lines

Tagged with: , , , ,

Remove empty characters at the end of each row


sed -e 's/ *$//' file.txt
No Comments »

Fish Shell Command History Meme

Tagged with: , , , , , , , ,

Use this command if you want to know your command usage stats in the fish shell.


grep -v "^\#" ".config/fish/fish_history"|awk '{print $1}'|sort|uniq -c|sort -rn|head -n10
No Comments »

Grep using Sed

Tagged with: , , , ,

View only lines that contain the word “string”


sed -n '/string/p'
No Comments »

Remove Empty Lines and Comments

Tagged with: , , , ,

Remove comments and blank lines from example.pl


sed '/ *#/d; /^$/d' example.pl
No Comments »

Graphical representation of sub-directories

Tagged with: , , , , , ,

This command shows a graphical representation of the current sub-directories.


ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'mand

Original Article

No Comments »

Remove Empty Lines

Tagged with: , , , , , , ,

Remove empty lines from a file using sed


sed '/^$/d' file.txt

Original Article

No Comments »