Searching Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching Problem
# 1  
Old 10-21-2009
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


Smilie
# 2  
Old 10-21-2009
Code:
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:
Code:
find /somedir| grep HelloWorld

or do it more "correct" with:
Code:
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 [code] and [/code] 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
# 3  
Old 10-21-2009
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
# 4  
Old 10-21-2009
I guess I don't understand.

If you have to search different directories, you can list them as 1st parameter behind find itself like
Code:
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:
Code:
find /dir1 /data/bla2 somedir3 -type f -name "somefile*" -exec grep -il "dieserinhalthier" {} \;

# 5  
Old 10-21-2009
yes i search the second solution:

Code:
 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
# 6  
Old 10-21-2009
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:

Code:
$> 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 <----------

# 7  
Old 10-21-2009
Hi zaxxon,

now the command is exactly what I had been making

Code:
 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"
Code:
Filename: ./yo
Eins
Zwei
Drei
Vier

Output---------
Code:
yoEins
yoZwei
yoDrei
yoVier

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

THANS FOR ANSWERING

Last edited by zaxxon; 10-21-2009 at 12:20 PM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Hsearch() problem when searching for strings.

I have written a code in C where the objective is to search for strings. There are two files: 1. Database file which has more than one billion entries. This file is read in argv in the C code below. The format of the file is like this: a.txt apple b.txt candle c.txt glue 2. There is another... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

2. Shell Programming and Scripting

Problem with the awk in searching the contents in a file

Hello all, I am a newbie in awk. I am struggling in this problem for a long.Actually I have two files, filea and fileb. File a is actually a search key through it I have to find the corresponding japanese tag from file b. filea contains the data like this: sm982882 sm1893548 sm2420025... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Shell Programming and Scripting

searching a file with a specified text without using conventional file searching commands

without using conventional file searching commands like find etc, is it possible to locate a file if i just know that the file that i'm searching for contains a particular text like "Hello world" or something? (5 Replies)
Discussion started by: arindamlive
5 Replies

4. UNIX for Dummies Questions & Answers

Searching

Hi guys, I have a very common issue :( im trying to work it out but I am still not used to it. my problem is searching. very often I should look for piece of string in a text file or a file itself: I want to learn some easy and professional commands to ease this routine for me. I want to be... (2 Replies)
Discussion started by: messi777
2 Replies

5. Shell Programming and Scripting

Problem with searching and then editing a file through shell.

Hi, I have searched through this forum as there are many similar entries but could'nt get one of them to work, either that or they were just different to what I needed. Basically I have a file, recordsDatabase. In this file are a few different fields. There is a unique identifier eg 001... (5 Replies)
Discussion started by: U_C_Dispatj
5 Replies

6. UNIX for Dummies Questions & Answers

searching

How would i search to find all the lines consisting of of only the letter "z" followed by any four characters? (1 Reply)
Discussion started by: trob
1 Replies

7. Shell Programming and Scripting

problem while searching in a file by 'AWK'

Hi , i am writing a script in which i am using following command to grep some string and then storing it's output to v, as like below :- v=$(awk -F, '{ if ( $NF ~ /DEV/ ) print $0 "_BLD01";else print $0 "_RC01" }' mytest) Here i am facing following issues:- 1. it is searcing DEV in the... (1 Reply)
Discussion started by: inderpunj
1 Replies

8. Shell Programming and Scripting

PERL: Searching for a string in a text file problem

Looking for a bit of help. I need to search for a string of words, but unfortunately these words are located on separate lines. for example the text output is: United Chanmpions Ronaldo Liverpool Losers Torres and my script code is print("DEBUG - checking file message"); while... (15 Replies)
Discussion started by: meevagh
15 Replies

9. UNIX for Dummies Questions & Answers

Searching in VI

Hi, I would like to do a search and replace on a file using vi. Something like this: :%s/dst_port=****//g I want to search the entire file and replace all text that does not match dst_port=**** with space or nothing. In other words delete everything except for dst_port=****. The four *... (1 Reply)
Discussion started by: andyblaylock
1 Replies

10. Shell Programming and Scripting

searching for {

Hello, I am having a hard time trying to do the following: I have a file that looks like this: 0 CacheMaxConn 4 64 0 RMThread 16 3423423 7 DataSource 0 /hello/sas/ses 0 {94545B4-E343-1410-81E4-08000000} 3 DDBE 3 ... (4 Replies)
Discussion started by: yotoruja
4 Replies
Login or Register to Ask a Question