how can i get the file name in which i found the data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how can i get the file name in which i found the data
# 1  
Old 08-05-2008
how can i get the file name in which i found the data

Ex :-
file.txt
<fruits>
<apple>redcolor<\apple>
<banana>yellow color and it is<\banana>
</fruits>

i have a number of files in my directory in above fashion.
i am searching for perticular data between the tags using this command

nawk -F">" '{print $2}' *.txt | nawk -F"<" '{print $1}' | grep word


Q:- how can i get the file name in which i found the data ?
# 2  
Old 08-05-2008
Assuming you have the pattern in the variable word:
Code:
 nawk -F"<|>" -v s="$word" '$0 ~ s{print FILENAME; print $3}' *.txt

Regards
# 3  
Old 08-05-2008
thanx for u replay.

i found some problem

<fruits>
<apple>redcolor<\apple>
<banana>yellow color and it is<\banana>
</fruits>

the problem is if given word is red color it is giving correctly

but if the given word is TagName like apple or banana it should give the result
# 4  
Old 08-06-2008
Hi,

I am not clear your question, can u explain me clearly.

suppose u want to print pattern matching filename use the following command

grep -l "string" *

the above command list what are the files having the string name in your current directory.
# 5  
Old 08-06-2008
i found this awk erference manual to be of much help
AWK Language Programming - Table of Contents
i still havent read to the part where it explains what you ask tho :P
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Data recovery from lost+found in centos6.2

Respective sir, I have Centos-6.2 on my system(P-4,1GB RAM, 80GB hdd).While working on my system I just face one problem my all folder get symbol of lock so I go for open terminal but my terminal is also not opened.So I shut down my pc without proper way.After restart my system I... (1 Reply)
Discussion started by: Kiran ursal
1 Replies

2. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

3. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

4. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

5. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

6. Shell Programming and Scripting

Delete a pattern present in file 2 from file 1 if found in file 1.

I have two files File1 ==== 1|2000-00-00|2010-02-02|| 2| 00:00:00|2012-02-24|| 3|2000-00-00|2011-02-02|| File2 ==== 2000-00-00 00:00:00 I want the delete the patterns which are found in file 2 from file 1, Expected output: File1 ==== (5 Replies)
Discussion started by: machomaddy
5 Replies

7. Programming

ORA-01403: no data found exception in cursor

Hi All, I have cursor which is about to fetch 4,00,000 records and then I am performing the action in cursor. I am running this sql using unix script. But after some time , I see the job is no more exists but sql is also not completed. what might be the reason. (1 Reply)
Discussion started by: rshivarkar
1 Replies

8. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies

9. Red Hat

How to recover data from lost+found

Hi All, I am facing a problem of filesystem corruption,where i am trying to recover data with fsck -f <device name> ,now it restore the corrupted data in lost+found directory.Please let me know how to recover the data from lost+found directory. Thanks, Shailesh (1 Reply)
Discussion started by: sbapotikar
1 Replies

10. Solaris

Deletion of Data from Lost+Found Directory

Hie I am running a sun solaris server of about 300 gigabytes disk capacity. The problem is that the machine has been having problems over the past year and at times the machine would just freeze or hang and had to be re-booted. Consequently there are too many entries in the lost+found... (1 Reply)
Discussion started by: Ranganai
1 Replies
Login or Register to Ask a Question