Search This Blog

Edit a text file using sed

  • Replace a word
    • text.txt file contains following line:
      ios
      
    • Run the following command to replace ios with android:
      sed -e "s/ios/android/g" -i .bak text.txt
      
  • Append a word
    • text.txt file contains following line:
      leopard
      
    • Run the following command to append lion after leopard:
      sed -e "s/leopard/& lion/g" -i .bak text.txt
      
  • Append a token to each line
    • Run the following command to append 0 to each line:
      sed -e "s/$/ 0/g" -i .bak text.txt
      



No comments:

Post a Comment