Q: delete a line from a file containing the exact number and quit on the first find & delete I am trying to delete a numerical value once only from a file where there could be more than one instance of that value.
file_input=  
2  
4  
18  
8  
8  
10  
12  
14  

I need to delete '8' but only once and i want to keep '18'. The final result should be in file_output as such:  
2  
4  
18  
8  
10  
12  
14  

I tried sed '/8/d', grep -v -w '8' and awk '$1 !=8' but they all delete 8, 8, and 18.

A: I suggest with GNU sed:
sed '1,/^8$/{/^8$/d}' file

Output:

2
4
8
10
12
14

From first line to line which contains only 8 (1,/^8$/) delete line which contains only 8 (/^8$/d).

See: man sed and The Stack Overflow Regular Expressions FAQ

A: Here's the awk version
$ awk '!($1==8 && !c++)' ip.txt
2  
4  
18  
8  
10  
12  
14  



*

*$1==8 && !c++ check if first field is exactly 8, if so check whether c evaluates to false(c will get incremented and so won't be false next time)


*

*we don't want to print when this is true, hence the outer negation


*this will work even if there are whitespaces around the first field, like in the given sample in question

