Searching Problem

Hi,

I would like produce follow console-printing if I searching a string (but for all hits):

e.g.: Datei1HelloWorld

Option -H is not possible on my unix.

Thanks for help!

---------- Post updated at 02:36 AM ---------- Previous update was at 02:34 AM ----------

my actually solution:

find *datei* -exec grep "HelloWorld" {} \; -print

:frowning:

find *datei* -exec grep "HelloWorld" {} \; -print

You have to start with a directory - not sure if *datei* is really a directory..

You can either be lazy and do:

find /somedir| grep HelloWorld

or do it more "correct" with:

find /somedir -type f -name "HelloWorld" -print

The man page is often a good help.

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

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

First of all, 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

```text
 and 
```

by hand.)

Second, 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.

Third, 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

Thanks zaxxon,

I search multiple diroctorys. and then the filename is given only when there are multiple files with this wildcard. I would like but generally each file matches the format printing:
DateiInhalt.

---------- Post updated at 03:35 AM ---------- Previous update was at 03:31 AM ----------

I searching a string in a file...and would like the console-printing:

FileContent e.g. file1HelloWorld

I guess I don't understand.

If you have to search different directories, you can list them as 1st parameter behind find itself like

find dir1 dir2 /dirlala /tmp/bla -type f -name "file1" ...

If you want to check contents of a file with grep is ok and to see which filename has it can be obtained by grep -l (lowercase L).

Maybe you are looking for something like this:

find /dir1 /data/bla2 somedir3 -type f -name "somefile*" -exec grep -il "dieserinhalthier" {} \;

yes i search the second solution:

 find /dir1 /data/bla2 somedir3 -type f -name "somefile*" -exec grep -il "dieserinhalthier" {} \; 

but addition I woult like to display the content of the file....

Somefile1DieserInhaltHier

Ok, how you can specify filenames you are looking for and in which directories should be clear by now. Here is an example that might be ok for you:

$> find . -type f -exec grep -l OCT {} \; | while read LINE; do echo "Filename: $LINE"; cat $LINE; echo "----------> Trenner <----------"; done
Filename: ./yo
eins
zwei
OCT
drei
vier
----------> Trenner <----------
Filename: ./infile
16-SEP-2009 09:11:47 10.65.4.24
16-SEP-2009 09:11:47 10.3.4.11
30-SEP-2009 10:11:47 10.3.4.11
1-OCT-2009 10:11:47 10.65.4.24
6-OCT-2009 10:11:47 10.3.4.11
6-OCT-2009 12:31:01 10.3.4.11
16-OCT-2009 11:11:47 10.65.4.24
17-OCT-2009 11:11:47 10.65.4.24
18-OCT-2009 11:11:47 10.3.4.11
----------> Trenner <----------

Hi zaxxon,

now the command is exactly what I had been making

 find *datei* -exec grep "HelloWorld" {} \; -print
 

my big problem:
he finds in a file several hits, he even prints out the name and then all matches. I wish that he always print names and content

e.g. Search file with content "e"

Filename: ./yo
Eins
Zwei
Drei
Vier

Output---------

yoEins
yoZwei
yoDrei
yoVier

I have no experience in skript programming. I know only simple unix comands.

THANS FOR ANSWERING

Also use code tags for your examples of input and output like in your former post please.

No, your command

find *datei* -exec grep "HelloWorld" {} \; -print

shows only the filename, no content at all.

Schwere Geburt :slight_smile: now I know what you want:

find . -type f -exec grep -l OCT {} \; | while read LINE; do awk -v l=$LINE '{print l":"$0}' $LINE; done
./yo:eins
./yo:zwei
./yo:OCT
./yo:drei
./yo:vier
./yo:OCT
./yo:fuenf
./yo:sechs
./infile:16-SEP-2009 09:11:47 10.65.4.24
./infile:16-SEP-2009 09:11:47 10.3.4.11
./infile:30-SEP-2009 10:11:47 10.3.4.11
./infile:1-OCT-2009 10:11:47 10.65.4.24
./infile:6-OCT-2009 10:11:47 10.3.4.11
./infile:6-OCT-2009 12:31:01 10.3.4.11
./infile:16-OCT-2009 11:11:47 10.65.4.24
./infile:17-OCT-2009 11:11:47 10.65.4.24
./infile:18-OCT-2009 11:11:47 10.3.4.11

Hi Zaxxon,

THANK YOU FOR YOUR HELP....

I need nawk but its works!

Thank you very much. greedings

---------- Post updated at 11:11 AM ---------- Previous update was at 11:00 AM ----------

Addition I would like the same for zip-Files

With gzgrep it don�t work :frowning:

---------- Post updated at 11:30 AM ---------- Previous update was at 11:11 AM ----------

I have one more mistake:

The format is great but...

I search in many files:
fileA:

  eins
  OCTa
  zwei

fileB

  drei
  OCTb
  vier

fileC

  f�nf 
  OCTc 
  OCTd

solution:

fileaOCTa
filebOCTb
fileCOCTc
fileCOCTd

Also only the one content of the file who I search "OCT"

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

First of all, 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

```text
 and 
```

by hand.)

Second, 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.

Third, 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