grep for a special range

hi,
i search a command to get follow solution:

file:
21082009mueller01testtest
22082009mueller02testtest
23082009mueller03testtest
24082009mueller02testtest
25082009mueller03testtest

Solution:
I search all lines with "mueller02" at the range 8 to 17

It is possible with

greb "^therange" mueller02 file 

???

---------- Post updated at 11:15 AM ---------- Previous update was at 11:14 AM ----------

Important is the search of the exact range !!!!!!! Thanks for answering

grep '^.\{8\}mueller02' file1
22082009mueller02testtest
24082009mueller02testtest

The "m" of mueller starts at posistion 9.

(was ist greb?)

Wow thats it! Thank you!

Is it possible to search with a Connection e.g.

grep '^.\{8\}mueller02' file1 + grep '^.\{17\}test' file1

in one Command?

What what do you want to search for?

If you only want to extend the search of muellerXX, then

grep '^.\{8\}mueller02test' file1

To do multilple searches use extended regular expresions with grep:

grep -E "^.{8}mueller02|^.{17}test" file1

you can use gawk as well it is easy using it.

gawk '(substr($0,9,9)=="mueller02") {print}'  file.txt

You don't need to grep twice

grep '^.\{8\}mueller02test' file

or for second test as pattern

grep '^.\{8\}mueller02.\{4\}test' file

---------- Post updated at 12:27 PM ---------- Previous update was at 12:27 PM ----------

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote