![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| backup spanning multiple DVDs | dangral | UNIX for Dummies Questions & Answers | 0 | 12-24-2007 02:02 PM |
| Delete multiple lines containting a variable string using SED. | selkirk | UNIX for Dummies Questions & Answers | 2 | 04-27-2007 07:08 PM |
| Need to delete multiple lines in a file. | kangdom | Shell Programming and Scripting | 6 | 10-16-2006 11:02 AM |
| delete multiple empty lines | whatisthis | Shell Programming and Scripting | 3 | 11-09-2005 05:42 PM |
| Delete multiple lines w/ sed | bookoo | Shell Programming and Scripting | 2 | 07-25-2003 10:03 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
using sed command to delete a string spanning multiple lines
file1 contains the following data
sssssssssss firstline secondline pppppppppp ssssssssss Using sed comamnd i am trying to delete firtsline secondline. so, output should be sssssssssss pppppppppp ssssssssss I tried in the following the way, but it is not working. sed s/"firstline[\r\t]secondline"// file1 |
|
||||
|
I Think this would delete the lines containing the pattern secondline. But the OP wanted to remove the pattern from the line.
I think you can use like Code:
sed 's/.*line//g' file1 or sed -e 's/firstline//g' -e 's/secondline//g' file1 |
|
||||
|
i forgot to mention, the input file can be
sssssssssss firstline secondline pppppppppp ssssssssss or sssssssssss firstline secondline pppppppppp ssssssssss ie firtsline secondline can be on the same line or on different lines, and we should only delete only if we can find both firstline and secondline continueously. otherwise it should be retained |
|
||||
|
Input
Code:
$ >cat file1 sssssssssss firstline secondline pppppppppp ssssssssss sssssssssss firstline secondline pppppppppp ssssssssss Code:
$ > sed -e 's/firstline//g' -e 's/secondline//g' file1 sssssssssss pppppppppp ssssssssss sssssssssss pppppppppp ssssssssss |
|
||||
|
Acccording to my requirement it should not delete third 'firstline' because there is no 'secondline' string after that. it should delete only if 'firstline secondline' comes contionusly. It can have \n in between.
bash-3.00$cat file1 hello ssssssssss firstline secondline pppppppppp ssssssssss sssssssssss firstline secondline pppppppppp ssssssssss firstline ssssssssssss bash-3.00$ sed -e 's/firstline//g' -e 's/secondline//g' file1 ssssssssss pppppppppp ssssssssss sssssssssss pppppppppp ssssssssss ssssssssssss bash-3.00$ |
|
||||
|
Quote:
line after line Code:
firstline secondline Code:
firstline secondline |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|