简体   繁体   中英

How to use sed to delete a line that has some determined fields?

I have this.txt file in linux that looks like this:

Car;Weight;Year;Origin   
Ford Focus;85.2:75:US
Audi A4;78.2;80;Europe
Ford Focus;77.6;90;US

(The actual file is longer but is for you to have an idea of what it looks like) The thing is that I want to delete the line with the Ford Focus whose weigh is 85.2 and year 75, I've tried using sed this way:

sed -i `/Ford Focus/85.2/75/d` cars.txt

But it doesn't work, any idea of how could I do it?

With ; and : as possible field separators and awk :

awk -F '[;:]' '$1=="Ford Focus" && $2=="85.2" && $3=="75"{next} {print}' cars.txt

Output:

Car;Weight;Year;Origin   
Audi A4;78.2;80;Europe
Ford Focus;77.6;90;US

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM