How can i grep for a specific pattern of numbers like
1000010000000
in a whole file - the line has to have thes numbers at the beginning not somewhere else...
How can i grep for a specific pattern of numbers like
1000010000000
in a whole file - the line has to have thes numbers at the beginning not somewhere else...
For a search with that exact string 1000010000000
at the beginning of the line, a
grep "^1000010000000"
is ok.
More flexible is a pattern like this (as example):
grep -P "^1[0]{4,4}1[0]{7,7}" <your_file>
Explanation:
^1[0]{4,4}1[0]{7,7}
^
assert position at start of the string1
matches the character 1 literally[0]{4,4}
match a single character present in the list below
{4,4}
Exactly 4 times0
the literal character 0
1
matches the character 1 literally[0]{7,7}
match a single character present in the list below
{7,7}
Exactly 7 times0
the literal character 0
grep '^1000010000000' filename
The caret means beginning of line.
Edit:
Just found a helpful tutorial for this sort of thing here.
You can do
sed -n '/^1000010000000/p' file
Explanation
The -n
means suppress normal output, so we only print the lines we want.
The /^1000010000000/
means match line with the pattern at the beginning of the line. The ^
is an anchor meaning the start of a line.
The p
prints out the matched line.