O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required