Get List of Unique File Names


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get List of Unique File Names
# 1  
Old 04-02-2010
Data Get List of Unique File Names

I have a large directory of web pages. I am doing a search through the web pages using grep and would like to get a list of unique file names of search results. The following command works fine to give me a list of file names where term appears:

grep -l term *.html

However, since these are web pages, the term that I'm looking for might also be an html tag (i.e. <strong>, <body>, etc) and I don't want those to to be in the search results. To filer out certain tags, I'm using the following command:

grep term *.html | grep -v filter

But if term appears more than once in a web page, the file name shows up more than once in the results.

Is there a way to get a unique list of filenames after applying a "grep filter (grep -v)"? Piping things to grep -l doesn't seem to work.


I've tried using these commands, but they don't work:
  • grep term *.html | grep -v filter | grep -l
  • grep term *.html | grep -v filter | grep -l term
  • grep term *.html | grep -v filter | xargs grep -l
  • grep -l term `grep term *.html | grep -v filter`
Smilie Ray
# 2  
Old 04-02-2010
hi,
use UNIQ command
grep term *.html | grep -v filter|uniq
# 3  
Old 04-02-2010
Code:
grep term *.html | grep -v filter | cut -d":" -f1 | sort -u

Code:
grep -l "[^/<]term[^>]" *.html

# 4  
Old 04-02-2010
anbu23,

Thank you, that first command was the one I was looking for. That second command will also come in handy.

Smilie Ray
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

2. Shell Programming and Scripting

Discover unique names and organize

I'm attempting to write a script that will look into a directory, discover all unique names, create directories for their prefix names and place the files inside. I do this now one by one with a simple script but I'd like to automate the process. The directory would contain something like: ... (6 Replies)
Discussion started by: scribling
6 Replies

3. UNIX for Dummies Questions & Answers

List Directory names which have the file

Hi All, Can any one help me to list out the directory names which contain the specified file. See for example File name : file.201307014.LKT Have the directory structure as below. /app/work/data/INDIA/file.201307014.LKT /app/work/data/AMERICA/file.201307014.KTP... (5 Replies)
Discussion started by: Balasankar
5 Replies

4. Shell Programming and Scripting

List the file names that differ

Hello, I have two directories - prev and current . They both have same multiple subdirectories and files. Now the current directory can have some updated files and some new files added that is not in prev. I want to find the list of file names that differ. I am doing this because i can not... (2 Replies)
Discussion started by: jakSun8
2 Replies

5. Shell Programming and Scripting

How to get the dates from a list of file names?

Hi All, I have a .txt file with the list of filenames as given below. /dev_data/dev3/ctl/20120622_Employee.txt /dev_data/dev3/ctl/20120623_Employee.txt /dev_data/dev3/ctl/20120624_Employee.txt I want to read this file & write the dates alone from the filenames into a .done file. ... (6 Replies)
Discussion started by: dsfreddie
6 Replies

6. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

7. Shell Programming and Scripting

List unique values and count instances in .csv file

I need to take the second column of a .csv file and count the number of instances of each unique value in that same second column. I'd like the output to be value,count sorted by most instances. Thanks for any guidance! Data example: 317476,317756,0 816063,318861,0 313123,319091,0... (4 Replies)
Discussion started by: batcho
4 Replies

8. Shell Programming and Scripting

get file names from the list

Hi Experts, Here is my scenario: Am maintaining a file which has list of logs with complete path and file names like bleow a/b/c/Daily/file1_20111012.log d/e/f/Monthly/file1_20111001.log g/h/Daily/file1_20110120.log i/Daily/file1_20110220.log How to copy the file names frm the list... (7 Replies)
Discussion started by: laxm
7 Replies

9. Shell Programming and Scripting

List of file names

I have the following list of file names stored in $fnames, so that if I do foreach f ($fnames) echo "$f" end I will get n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run1 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run2 n02-z30-sr65-rgdt0p50-dc0p002-16x12drw-run3... (3 Replies)
Discussion started by: kristinu
3 Replies

10. UNIX for Dummies Questions & Answers

Help with list of latest file names

Hi Gurus, I need to list only those files which are most recent and the latest log file. For example if I have the following file list: JOB001.LOG_00uv02_00006 - Jul 7 12:16 JOB001.LOG_00vi0t_00001 - Aug 4 21:58 JOB001.LOG_00vi0t_00002 - Aug 5 09:15 JOB001.LOG_00vi0t_00003 - Aug 5... (6 Replies)
Discussion started by: shash
6 Replies
Login or Register to Ask a Question