Question

I tried the below greps but they don't retrieve any thing. how to retrieve only lines that contain 624 at the beginning of the file and not 1624 for ex, nor 624 in other fields? Fields are separated by |

grep '^624$' names.dmp | less 
grep -Fx 624 names.dmp | head

many thanks

Carol

Was it helpful?

Solution

If data is space separated:

awk '$1=="624"' names.dmp

If your grep supports -w you can use:

grep -w "^624" names.dmp

-w, --word-regexp force PATTERN to match only whole words

or

grep  "^624 " names.dmp

(See the space after 624)


PS If data is separated by |, then you need this awk

awk -F\| '$1=="642"' names.dmp

And for grep this should do:

grep "^642|" names.dmp
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top