Click on red strip to expand it
1. Replace all occurrence
|
1. Replace all occurrence
Ram in
Inputfile with
Shyam and save the result in
Outfilesed 's/Ram/Shyam/' Inputfile >Outfile
2. Replace all occurrence of multiple string
|
2. Replace all occurrence
Ram and
Sita in
Inputfile with
Shyam and
Geeta respectively, and save the result in
Outfilesed -e 's/Ram/Shyam/; s/Sita/Geeta/' Inputfile >Outfile
3. Reading sed commands from a file
|
3.
Reading Commands From a File: I have multiple strings saved in
Inputfile and want to replace them with multiple strings saved in a file
string and save the in
Outfilesed -f string Inputfile >Outfile
4. Substituting Flags: to control the replacement in file
|
4.
Substituting Flags: There are 4 kinds of substitutions:
- g, replace all occurrences.
- A number, the occurrence number for the new text that you want to substitute.
- p, print the original content.
- w file: means write the results to a file.
Extract Part of a FASTA Sequences with Position by python script
HERE
5. Limiting sed in a file
|
5.
Limiting sed in a file: By default, Sed command processes your entire file. However, you can limit the sed command to process your file in different ways:
- A range of lines.
- following command will replace string in second line only
sed '2s/Ram/Shyam/' Inputfile >Outfile
A pattern that matches a specific range.- following command will replace string in
second and third line only
sed '2,3s/Ram/Shyam/' Inputfile >Outfile
- Following command will replace string in
second line to the end of the file only
sed '2,$s/Ram/Shyam/' Inputfile >Outfile
6. Delete Lines in a file with sed
|
6. Delete Lines in a file with sed : The delete (d) flag deletes the text from the stream, not the original file.
- following command will delete second line
sed '2d' Inputfile >Outfile
- following command will delete
second and third linesed '2,3d' Inputfile >Outfile
- following command will delete
second line to the end of the file.
sed '2,$d' Inputfile >Outfile
Post a Comment