Monday, September 28, 2020

SED - Basics

 

  • Comment :  #

  • Escape sequence :  \  (backward slash)

  • Find and replace string in a file

    • sed  ‘s/find_string/replace_string/g’ filename.c > outputfilename.c

  • To make the backup of  file, use –i options

    • sed  -i.bak ‘s/find/replace/g’ filename.c

      • it makes the changes in filename.c but keeps the backup of that file in filename.c.bak

  • It can also do all the operation via single command line also instead of file operation.

    • Datafile  = echo   ‘$1’  |  sed ‘s/ zled/Zled/’

  • Instead of using –i".bak”, use mv command

    • Sed “pattern” $filename > temp

    • mv temp $filename

  • Script 

  • List of commands

    • Printing – p

    • Deleting – d

    • Substitution – s

    • Range of selected line – comma

    • Multiple edits – e

    • Reading from file – r

    • Writing to file – w

    • Appending – a

    • Inserting – i

    • Changing – c

    • Next – n

    • Transform - y

    • Quit – q

    • Holding and getting – H & g

    • Holding and exchange – h & x

No comments:

Post a Comment

Minicom

 Installation sudo apt install minicom Configuration Giving permission to user for accessing the serial port chmod 666 /dev/ttyUSB0 after th...