Find in files issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find in files issue
# 1  
Old 11-19-2010
Find in files issue

So, I'm back with another, pretty much similar question. I've got a catalogue, with about 60k text files. Every file contains a single line of text with variable number of characters. Here are some examples, which will make my case easier to understand:

Example file 1.
Code:
[...]<item id="2506"/><item id="3000"/><item id="2506"/><item id="3000"/>[...]

Example file 2.
Code:
[...]<item id="2506"/><item id="3000"/><item id="3000"/><item id="3000"/>[...]

Example file 3.
Code:
[...]<item id="3000"/><item id="3000"/><item id="3000"/><item id="3000"/>[...]

Example file 4.
Code:
[...]<item id="2506" special_description="blablabla"/>[...]

Example file 5.
Code:
[...]<item id="2506" special_description="lololol"/>[...]

And I've got two issues.
Issue 1. I'd like to know how many '<item id="2506"/>' records do I have in the catalogue, with specific filenames added. So in the example case I'd print something like:
example file 1 name
example file 1 name
example file 2
Since Example file 1 contains the string two times, example file 2 contains only a single record, and 3,4,5 doesn't. Is it possible to do?

Issue 2. I'd like to find every record of <item id="2506" that has the special_description in it's arguments, and print out the special_description value.
I'd see it like this:
Filename(example file4) and here printed out the x characters after the <item id="2506", so I'd see the special_description. Final output:
example file 4 special_description="blablabla"
example file 5 special_description="lololol"

I'm sorry if it's a little chaotic. I've tried different arguments of grep, but failed at both cases.
Cheers.
# 2  
Old 11-19-2010
Try:

Code:
grep -cH '<item id="2506"/>' *

and this:

Code:
for i in *; do
        sed -n "s/.*\(special_description=\".*\"\).*/$i \1/ p" $i
done

# 3  
Old 11-28-2010
Sorry for the delay. It's not really working.
# 4  
Old 11-28-2010
For issue 1:
Code:
awk -v RS=" " '/id="2506"/{print FILENAME}' *

For issue 2:
Code:
for i in *; do
        sed -n  "/id=\"2506\"/ s/.*\(special_description=\".*\"\).*/$i \1/ p" $i
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Issue with deleting files through find

Hi, I have a script similar to this #!/bin/ksh cd /orcl/bir/eod_badfiles find ./ -type f -name "*.csv" -mtime +6 -exec rm -f {} \; find ./ -type f -name "*.bad" -mtime +6 -exec rm -f {} \; cd /orcl/bir find ./ -type f -name "*.log" -mtime +6 -exec rm -f {} \; This was working fine in one... (5 Replies)
Discussion started by: Gangadhar Reddy
5 Replies

2. Shell Programming and Scripting

Find command issue

Guys, Here is my requirement.. Sample.cfg file="*log.gz *txt.gz" sample.sh #!/bin/sh . $HOME/Sample.cfg find . -name "$file" -mtime +20 -exec ls -la {} \; Its not finding the given *log.gz and txt.gz files. Could anyone please help me? (8 Replies)
Discussion started by: AraR87
8 Replies

3. Shell Programming and Scripting

issue while moving files using find command

Hi Friends, I'm facinf issue while moving large files using find command.I've a scenario like i've to move one day older files from one directory to anothe directory.I'm using the below command. find $src_dir -name error -prune -o -type f -mtime +1 -exec mv {} $dest_dir \; some times... (1 Reply)
Discussion started by: mail2mura
1 Replies

4. Linux

find command issue

Hi, I am not root user. I am trying to find the file which has contains pattern "fvsfile" in root directory. If i run the find cmd then i got permission denied and all the files are listed include pattern files. i cant get file name yet find . print | xargs grep -i "fvsfile" I want... (2 Replies)
Discussion started by: Mani_apr08
2 Replies

5. Shell Programming and Scripting

Issue while moving files using find command

Hi All, I'm facing this below error when I move files using find command....Please help out...... $ find /home/aa/ab -mtime +90 -type f -exec mv -f {} /home/aa/ab/ac \; mv: 0653-405 /home/aa/ab/ac/MP_060520111245.csv and /home/aa/ab/ac/MP_060520111245.csv are identical. mv: 0653-405... (2 Replies)
Discussion started by: HemaV
2 Replies

6. Shell Programming and Scripting

Issue with Find Command

Hi All, I'm a bit new to Linux environment, moderately okay when it comes to Unix AIX. I'm facing an issue while trying to run a simple find command: $ for file in `find . -name *.*` > do > ls $file > done This is throwing the following error: Strangely, a few minutes... (4 Replies)
Discussion started by: adi_2_chaos
4 Replies

7. UNIX for Dummies Questions & Answers

ISSUE and ISSUE.NET files

In LINUX(CentOS, RedHat) is there a way to have the banner statement appear before the logon instead of after the logon? In UNIX and Windows the banner appears before a person actually logs on, what I'm seeing in LINUX is that it appears after the login(ftp, telnet, SSH). Thanks (0 Replies)
Discussion started by: ejjones
0 Replies

8. Shell Programming and Scripting

Little bit weired : Find files in UNIX w/o using find or where command

Yes , I have to find a file in unix without using any find or where commands.Any pointers for the same would be very helpful as i am beginner in shell scritping and need a solution for the same. Thanks in advance. Regards Jatin Jain (10 Replies)
Discussion started by: jatin.jain
10 Replies

9. UNIX for Advanced & Expert Users

find issue

I'm trying to use find command to generate a list of a files w/ a specific extension (.axv), but I would also like to exclude/grep out another directory completely from the search (Archive). I have been poking around various sites/forums and man pages and haven't figured this out. tb (2 Replies)
Discussion started by: bisston
2 Replies

10. Shell Programming and Scripting

An issue with find command.

Hi all, I have a shell script(ksh) which has the code as follows. ------------------ cd $mydir for i in `find ./ -type f -mtime +$k` do echo $i done ----------------------- And in $mydir , i have some files which have space in theie names like "Case att15". The out put of the... (6 Replies)
Discussion started by: rajugp1
6 Replies
Login or Register to Ask a Question