Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have figured out several line numbers that need to be deleted from a file.
Say lines_to_rm="8 9 10 11 34 35 78 79"
I have tried adding a "d" to each number & passing the "8d 9d 10d 11d" to sed in one go, it doesn't work.
From address ranges, I take it one can do consecutive lines like:
sed '8,9d' file
but apparently I can't do '8,9,14,15d'
any idea to do it in one line??
Thanks

====> 1. input file
$ cat myfile.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15====> 2. script
$ cat 5.sh
#!/bin/ksh
set -xDEL=d
cat <<EOF > sed.txt
8d
9d
10d
11d
34d
35d
78d
79d
EOFsed -f sed.txt myfile.txt
====> run 5.sh script
$ ./5.sh
+ DEL=d
+ cat
+ << EOF
+ > sed.txt
+ sed -f sed.txt myfile.txt
1
2
3
4
5
6
7
12
13
14
15Luke Chi

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |