suppose i have a file emp.txt containing the following lines.I want to extract lines beginning with sriram till rajesh with out knowing the line numbers and replace company1 with xyz company in those lines and rite to a file.
1|sriram|manager|company1|203
2|satish|director|company1|205
3|raghu|software|company2|305
4|ravi|designer|company3|203
.
.
.
98|rajesh|executive|company5|405
99|rajesh|engineer|company4|204
Sol : sed -ne '/.*|sriram|/,/.*|rajesh|/p' emp.txt | sed 's/|company1|/|xyz|/g'
First sed prints line containig sriram till first occurrence of line containing rajesh and replaces string company1 with xyz.
No comments:
Post a Comment