read line numbers , delete those lines and the previous ones with sed
Hi , i am having issue to delete specific lines directly to a file
from a filtered file i get these line numbers i want to delete : Quote:
By this i mean these lines deleted : Quote:
like this : My file content with the lines i want to delete from another file full of text : Quote:
Code:
#Here it counts how many lines need to be deleted |
Code:
sed -i -e '${prevl}d' outfile But you need to take into account during delete the line numbering will change. |
Note that your for loop reads the entire file n+1 times.
The following is more efficient Code:
while IFS= read -r lnvar |
Quote:
Confirm that the version of sed you're using supports the -i [--in-place] option. Try putting the -i option last to be sure the following argument isn't being seen as a SUFFIX...(shouldn't) Also, further to pan64's comment: Sort the file of line numbers inversely (largest to smallest), then delete largest first. That should avoid the line number changing issue. PS You are making a backup of the outfile first, yes? ;) |
Both codes are working perfect .
However all i had to do was to remove the same line number twice , because deleting the previous one would change the file itself . Basically is something like this : Code:
#Here it counts how many lines need to be deleted |
All times are GMT -5. The time now is 02:00 AM. |