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):
Name:Address:Phone:email Joshua Brown:42404 Transport Center:380-(605)964-4223:jbrown0@desdev.cn Margaret Elliott:24 Forest Plaza:48-(269)541-4040:melliott1@toplist.cz Gary Flores:76868 Westport Drive:86-(478)534-8313:gflores2@reference.com
my code:
#assuming $1 is the pattern that needs to be searched for #if found, delete the entire line sed -i '/$1/d' filename
Advertisement
Answer
sed -i 'Nd' filename
N means the line number , begin from 1