Linux command editing examples using cat, ed, and sed

Linux and UNIX – Fast command line editing examples using cat, ed, and sed. Here is why you need to use command line editing tools…


#1: Text editor takes time for small editing
#2: Use command line editing
#3: Save time and impress your friends [ read as look like an elite UNIX hacker 😉 ]

Take a quick look at some essential editing one-liners that can save you time and effort. Text-editing operations are normally done interactively, inside a text editor application. Some tasks, however, can be accomplished quickly and easily, right from the UNIX(R) command line. What’s more, these one-liners can be used in scripts to automate various editing procedures.

This article demonstrates basic text-editing techniques with three of the most primary command-line editing tools readily available on all systems: cat, ed, and sed. The editing examples that follow start with the simplest and most common constructs and work up to the more complex.

You may also find this small shell script handy – to replaces all occurrence of javascript from HTML file 🙂

Read more at developerworks : Save time with text editing one-liners

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

7 comments… add one
  • Anil Alpati Jun 16, 2008 @ 14:35

    I am facing problem while checking the text file in linux which is starting with minus sign

    cat “-abc.txt”

    Please send me the reply at your earliest.


    • Imed Chihi May 8, 2012 @ 10:30

      A more general “fix” for those situations is to use:

      $ cat ./-abc.txt

  • jose martin Jul 3, 2008 @ 9:02

    Atleast one among the following should work
    cat ?abc.txt
    cat “-abc.txt”
    cat -abc.txt

    Else you may rename that file to something normal by opening it in vi with command like:
    vi *abc.txt and when the required file opens in the vi, save it with a normal name.

  • dodobrain Dec 22, 2008 @ 14:56


    You use the option terminator for exactly this reason, i.e. non-option arguments have prefixed ‘-‘ char:

    cat — -abc.txt

    *None* of the above poster’s possible solutions will work, as the ‘-‘ char will persist even after quoting, escaping or globbing. If you aren’t convinced, you can try them out. The option terminator ‘–‘ (two hyphens) works on almost all GNU cmdline tools.

  • dodobrain Dec 22, 2008 @ 14:57

    err.. can’t preview/edit posts. Anyway, for the copy/pasta people:

    cat -- -abc.txt

  • Harshit Mar 17, 2012 @ 8:04

    for showning contain of -abc.txt

    cat / -abc.txt (use space between ‘/’ and ‘-‘)

    this is absolutely work.

  • manju Dec 23, 2014 @ 6:59

    i have *.cat,*.inf,*.sys file
    this is limited time file how to brack time….

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.