Txt

Byte sized tech know-how.

  • Home
  • About

Tag Archives: sed

07 Jul

Add Line Numbers

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


sed = filename.txt | sed 'N;s/\n/\t/' > filename_number.txt
admin Posted in Command Line, Linux command, line, Linux, number, numbering, sed, shellfu 3 Comments
12 May

Delete Leading Whitespace Using Sed

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

admin Posted in Command Line, Linux command, delete, leading, Linux, sed, whitespace Leave a comment
31 May

Sed Regular Expression Range

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/

admin Posted in Command Line, Linux command, expression, Linux, range, regexp, regular, sed Leave a comment
22 Apr

View some lines in a file

View from 1th to 5th line


sed -n '1,5p;5q' example.txt
admin Posted in Command Line, Linux command, file, line, Linux, sed Leave a comment
18 Apr

Remove Empty Characters at End of Lines

Remove empty characters at the end of each row


sed -e 's/ *$//' file.txt
admin Posted in Command Line, Linux end, line, remove, sed, whitespace Leave a comment
16 Apr

Fish Shell Command History Meme

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
admin Posted in Command Line, Linux awk, command, fish, grep, history, Linux, meme, sed, shell Leave a comment
06 Apr

Grep using Sed

View only lines that contain the word “string”


sed -n '/string/p'
admin Posted in Command Line, Linux command, grep, Linux, search, sed Leave a comment
12 Feb

Remove Empty Lines and Comments

Remove comments and blank lines from example.pl


sed '/ *#/d; /^$/d' example.pl
admin Posted in Command Line, Linux, Perl comments, commnad, delete, Linux, sed Leave a comment
08 Feb

Graphical representation of sub-directories

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

admin Posted in Command Line, Linux command, dir, grep, Linux, ls, sed, tree Leave a comment
07 Feb

Remove Empty Lines

Remove empty lines from a file using sed


sed '/^$/d' file.txt

Original Article

admin Posted in Command Line, Linux blank, command, empty, line, Linux, remove, sed, text Leave a comment

Post navigation

← Older posts

Categories

  • Code
  • Command Line
  • Configuration
  • CSS
  • HTML
  • internet
  • JavaScript
  • Linux
  • Mobile
  • Perl
  • PHP
  • Python
  • Ruby
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Fruitful theme by fruitfulcode Powered by: WordPress
↑