Grep serial numbers do not start with a specific prefix

I have this file (serials.txt) containing serial numbers:

S/N:175-1915011190
S/N:244-1920023447
S/N:335-1920101144
S/N:244-1920101149

Using grepor a similar tool, I want to select all the series NOT, starting with '244' I can select all "244" with grep -Eo '244-[0-9]*' serials.txt, but I want the other way around.
Sort ofgrep -Eo '(^244)-[0-9]*' serials.txt

The output should be (without S / N :)

175-1915011190
335-1920101144
+4
source share
4 answers

The following awkmay help you with this.

awk '!/S\/N:244/'   Input_file

EDIT: . The full line will be displayed above the code in the form of output, if you need to start from the serial number to the end on the output, and then it can help you.

awk -F':' '!/S\/N:244/{print $2}'   Input_file

EDIT2: Adding a solution is sedalso here for this.

sed -n '/:244/d;s/.*://;p'   Input_file
+1

-v grep , cut, :

grep -v ':244-' serials.txt | cut -c5-
+1

S/N:

grep -v ':244' serials.txt | cut -d':' -f2

Anti-grep for: 244, cuts with a separator: shows field 2.

+1
source
awk -F':' '$2!~/^244/{print $2}' file
0
source

Source: https://habr.com/ru/post/1691697/


All Articles