Skip to content

Delete a single line from a file with a unix shell script

I’m working with a simple shell script that needs to delete a single line from a file if a string entered at command line is found. Instead it deletes the entire contents of the file.

the data file is like this(each entry is on a new line):

Joshua Brown:42404 Transport Center:380-(605)
Margaret Elliott:24 Forest Plaza:48-(269)
Gary Flores:76868 Westport Drive:86-(478)

my code:

#assuming $1 is the pattern that needs to be searched for
#if found, delete the entire line
sed -i '/$1/d' filename



sed  -i 'Nd' filename

N means the line number , begin from 1

User contributions licensed under: CC BY-SA
1 People found this is helpful