10.11. Quick one-liners

Here’s a small collection of one-liners ([] means a space and [ ] means a tab).

's/\.$//g' Delete all lines ending with a period
'-e /abcd/d' Delete lines containing abcd
's /[][][]*/[]/g' Delete two or more spaces and replace with a single space
's/^[][]*//g' Delete one or more spaces at the beginning of a line
's/\.[][]*/[]/g' Delete a full stop followed by two or more spaces and replace with a space
'/^$/d' Delete all blank lines
's/^.//g' Delete the first character
's/COL\( . . .\)//g' Delete three characters following the letters COL
's/^\///g' Delete the leading slash from a pathname
's/[]/[ ]/g' Delete all spaces and replace with a tab
's/^[ ]//g' Delete all tabs from the beginning of the line
's/[ ]*//g' Delete ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.