Listing files without specific expression in the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Listing files without specific expression in the file
# 1  
Old 04-09-2012
Listing files without specific expression in the file

I am running Ubuntu 11.10

I have the following files.

Code:
geo2503r05690585.html  
geo2503r06020612.html 
geo2503r06250641.html 
geo2503r06490658.html  
geo2503r06830686.html  
geo2503r05860601.html  
geo2503r06130624.html  
geo2503r06420648.html  
geo2503r06590682.html  
geo2503r06870687.html

In each of them there should be a line with the following statement:

Code:
bla
bla
bla bla bla href=../../../../geopdf/geo bla bla bla
bla
bla

I want to check all the files. I want to know which files do not contain this pattern in the file, so that I can fix them.

Code:
href=../../../../geopdf/geo

I was thinking of using grep in some way. However grep will check each line, not just one instance of the expression in the file.
# 2  
Old 04-09-2012
Code:
grep -Fl 'href=../../../../geopdf/geo' geo*.html

will get you a list of files that do contain the string.

Since you are on Ubuntu your grep should also have a -L option:
Code:
grep -FL 'href=../../../../geopdf/geo' geo*.html

Which should get you a list of files that do not contain the string..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 04-09-2012
Thanks. I have been trying the following but there is some problem with it:

Code:
#!/bin/tcsh

set allFiles = `tree -fi | awk 'BEGIN{FS="/"; OFS="/"}; NF == 4 {print}'` 

foreach f ($allFiles)
  set fext = $f:e
  if ( "$fext" == "html") then
    set result = `grep "../../../../geopdf/geo" $f`
    if ( "$result" == "" ) then
      echo "Check file $f"
    endif
  endif
end

---------- Post updated at 04:36 PM ---------- Previous update was at 04:28 PM ----------

So now I have tried using your code and hope it works, because I do not know if I missed changing a file. And in reality there are 886 of them.
Code:
#!/bin/tcsh

set allFiles = `tree -fi | awk 'BEGIN{FS="/"; OFS="/"}; NF == 4 {print}'` 

foreach f ($allFiles)
  set fext = $f:e
  if ( "$fext" == "html") then
    grep  -FL "../../../../geopdf/" $f
  endif
end

# 4  
Old 04-09-2012
Well if you run both commands through wc -l and you add up those numbers you should get 886, no?
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 04-09-2012
That way I can check. Very good.

---------- Post updated at 05:03 PM ---------- Previous update was at 04:58 PM ----------

I am a bit stuck on how to use the wc command on this

Moderator's Comments:
Mod Comment This thread has gone far enough. The problem posted has far more complexity than the basic usage of the wc command. Please avoid posting random untested input data such as bla and no matching output data.
Ps. As you hav been advised umpteen times on this board, we strongly advise that nobody uses csh for any unix systems work.

Last edited by methyl; 04-09-2012 at 07:29 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

2. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

3. Shell Programming and Scripting

Request for shell script for listing directories, subdirs containing specific files.

I'm looking for a script which outputs the list of directories and sub directories from root level consisting of specific files. For instance I want shell script to list all the directories and subdirectories containing .txt files.:wall: (4 Replies)
Discussion started by: super210
4 Replies

4. Shell Programming and Scripting

Printing several lines of a file after a specific expression

Hello, I want to print a number of lines of a file after a specific expression of a line. I have this sed command but it prints only 1 line after the expression. How could I adapt it to print for instance 10 lines after or 15 lines after ? sed -n '/regexp/{n;p;}' Thx & Regs, Rany. (5 Replies)
Discussion started by: rany1
5 Replies

5. Shell Programming and Scripting

Script for listing specific filename in 3 directory

I used to work in perl but I would like to try now bash. Here's my problem I wanted to search for specific filename (ls -ltrh) on 3 directories.. Example ls -ltrh | grep "string" /dir1 /dir1/dir2 /dir1/dir2/dir3 I wanted to get the result to be copied on a different directory. Sample... (2 Replies)
Discussion started by: lhareigh890
2 Replies

6. Shell Programming and Scripting

Perl regular expression for exclude specific ip range

I need regular expression for excluding specific range. e.g. Input Data is 10.10.10.50 67.172.15.15 10.10.10.15 78.122.105.108 I would like to extract only 67.172.15.15 & 78.122.105.108. I tried with something like /(^10.10.10)/ but it's not working. Please help me on this (17 Replies)
Discussion started by: nrbhole
17 Replies

7. Shell Programming and Scripting

capture specific listing in the ls -l

Hi, my desired output needs only that has *.pdf ls -l *.pdf error: arg list too long so I have redirected ls -l > file.txt therefore, I get the following details in the file -rw-r--r-- 1 devusr devgrp 848015 Aug 11 15:13 0000795769.pdf -rw-r--r-- 1 devusr devgrp ... (3 Replies)
Discussion started by: techmoris
3 Replies

8. Shell Programming and Scripting

Replace if regex on specific column matches expression?

I am attempting to convert rewrite rules to Nginx, and since due to the mass amount of rewrites we must convert, I've been trying to write a script to help me on a specific part, easily. So far I have this: rewrite ^action/static/(+)/$ staticPage.php?pg=$1&%$query_string; What I want done... (5 Replies)
Discussion started by: EXT3FSCK
5 Replies

9. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question