Search This Blog

Saturday, October 26, 2019

SED COMMANDS

SED COMMANDS

Insert a blank line after each line /Insert two blank lines
  • sed G filename.txt
  • sed 'G;G' filename.txt
Delete the blank lines
  • sed '/^$/d' filename.txt
Insert 5 spaces to the left of every lines
  • sed 's/^/     /' filename.txt
To delete the particular line
  • sed '10d' filename.txt
To delete the lines range from p to q
  • sed '5,10d' filename.txt
To delete nth to end line
  • sed '10,$d' filename.txt
To delete the matched pattern
  • sed '/Nagaraju/d' filename.txt
To delete the lines which matches the pattern and 5 lines after to that pattern
  • sed '/Nagaraju/,+5d' filename.txt 
To print the lines range from 10 to 50 of the file
  • sed -n '10,50p' filename.txt
To print the lines except that range from 5 to 10
  • sed -n '5,10d' filename.txt
To print the particular line and to print the lines from 5 to end of the line
  • sed -n '10p' filename.txt
  • sed -m '5,$p' filename.txt
To print the line which matches the pattern
  • sed -n /Nagaraju/p filename.txt
To prints lines from the nth line of the input ,up to that line matches the pattern ,if the pattern lines doesn't found then it print up to the end of the file
  • sed -n '1,/Nagaraju/p' filename.txt
To replace the pattern matches in the entire file with g without g current position of the line
  • sed 's/Raju/Nagaraju/g' filename.txt
To replacing the nth occurrence of the pattern

  • sed 's/Raju/Nagaraju/2' filename.txt
To replacing pattern on a specific line number 
  • sed '10 s/Raju/Nagaraju/' filename.txt
To replacing the pattern on a defined range and ignoring the case
  • sed '10,20 s/Raju/Nagaraju/i' filename.txt
Replace one pattern followed by the another pattern
  • sed '/is/ s/Raju/Nagaraju/' filename.txt
Replace a pattern with other except in the nth line
  • sed -i '5!s/Raju/Nagaraju/' filename.txt
How to displace the alternative line
  • sed -n '1~2p' filename.txt
How to print pattern1 to pattern 2
  • sed -n '/pattern1/,//pattern2/p' filename.txt 

Tar the file
tar -cvf filename.tar filename
Untar the file
tar -xvf filename.tar

No comments:

Post a Comment

What is the sanity checks you have done for STA?

 Sanity checks for STA: Linking Checks: We need to check., is there any missing modules or missing pins in a library. this is done by link c...