SED command In Linux O.S
SED command in UNIX is stands for stream editor and it can perform lot of function on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace.
cat <txt file> | sed 's/<old word><new word>'
SED command in UNIX is stands for stream editor and it can perform lot of function on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace.
- Replacing or substituting string
sed 's/unix/linux/' a.txt
- Replacing existing with new characters
sed 's/<old word><new word>' <txt file>
or
cat <txt file> | sed 's/<old word><new word>'
- Numbering of txt file and stream edit by sed
cat -n <txt file> | sed 's/<old word><new word>'
- if you want to replace all the message or word in txt file
sed 's/<old word>/<new word>/g' <txt file>
- change all first-word according to need of a txt file
sed 's/^/<new word' <txt file>
or
- if you want to change in all the line
sed 's/^/<new word/g' <txt file>
- when you want to add new word end of each lines
sed 's/$/<new word want to add> <txt file>
- When need each line spacing means after every line give one line space
sed G a.txt
- print only selected lines
sed -n <selected lines >p <txt file>
- if you want to delete lines according to need
sed <no of line>d <txt file>
- if you want to perform multiple operation user -e synatx
sed -e '2d' -e 'G' <txt file>
Comments
Post a Comment