473,500 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

grep text file line by line and grep a directory for a match of each line

16 New Member
Hi everyone,

This is my first time posting to the UNIX form and it might be a strange request, but I believe I have most of the pieces.

Here's the overall goal -- I am trying to find the links in a large web site that are linked to files over 2000k.

I used the command line to find all files on the server that are larger than 2000k by using the following:

Expand|Select|Wrap|Line Numbers
  1. find ./ -size +2000c > files_over_2000_bytes.txt
  2.  
And I know how to grep all the files in the web site to find a certain word by using the following:

Expand|Select|Wrap|Line Numbers
  1. grep -nr Something * > Something.txt;
  2.  
Since I haven't used awk except for way back in '98, I am at a loss for how I could place these two commands together.

In any type of language that I am familiar with, I would make a function out of the first line.

Then I would create another function to read each line within the text file and place it into a variable.

Then I would grep the web site using the variable.

So, I have the logic, but I do not know the syntax.

Can anyone help me?

Thanx n advance
Apr 3 '09 #1
6 8971
gpraghuram
1,275 Recognized Expert Top Contributor
You want to embedd the whole logic in a AWK program? or whats ur requirement?

raghu
Apr 3 '09 #2
kronus
16 New Member
This is what I came up with:

Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2.  
  3. while read LINE
  4.  
  5. do
  6.  
  7. grep –nr $LINE * > matched_line.txt
  8.  
  9. done < files_over_2000_bytes.txt
  10.  
Apr 3 '09 #3
ghostdog74
511 Recognized Expert Contributor
use the -f option of grep, eg
Expand|Select|Wrap|Line Numbers
  1. grep -f file1 file2
  2.  
Apr 4 '09 #4
ghostdog74
511 Recognized Expert Contributor
use the -f option of grep, eg
Expand|Select|Wrap|Line Numbers
  1. grep -f file1 file2
  2.  
Apr 4 '09 #5
kronus
16 New Member
I don't know if I understand your reply, because I am trying to read each individual line of file1 to grep the entire web site.

So are you saying that I should write:
Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2.  
  3. grep –f files_over_2000_bytes.txt * > matched_line.txt
  4.  
  5.  
Apr 6 '09 #6
kronus
16 New Member
I have started looking at my own post and I started to think that maybe this wasn't making much sense to anyone other than myself.

Say I have a file with the following:
Expand|Select|Wrap|Line Numbers
  1. /var/www/vhosts/something.com/images/1.jpg
  2. /var/www/vhosts/something.com/images/2.jpg
  3. /var/www/vhosts/something.com/images/3.jpg
  4. /var/www/vhosts/something.com/images/4.jpg
  5. /var/www/vhosts/something.com/images/4.jpg
  6.  
Let's call this file "files_over_2000k.txt"

What I would like to do is grep the entire web site using each line from "files_over_2000k.txt" to find any links within any page for "1.jpg," "2.jpg," etc... and place the results of where they are located, within another text file called "matched_line.txt"
Apr 6 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
13765
by: Noam Dekers | last post by:
Hi all, I would like to find a word stored in a text file. Structure: I have one file named keyWords.txt that stores some key words I'm interested in finding. In addition I also have a file...
6
2642
by: Jocknerd | last post by:
I'm a Python newbie and I'm having trouble with Regular Expressions when reading in a text file. Here is a sample layout of the input file: 09/04/2004 Virginia 44 Temple ...
2
1975
by: John Crouse | last post by:
I have a text file like so: ben amy jerry ann john and would like to alphabetize each line like so:
12
452
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
4
7367
by: Andyza | last post by:
I'm using FileSystemObject to open and write to a tab delimited text file. First, I connect to a database and select some data. Then I create the text file and insert each record in the text...
5
15158
by: dean | last post by:
sSQL = " update SELECTED_NODES " " set LABEL_S = 'Y' " " where NODE_I in " " ( " " select NODE_I " " from " " ( " " select ONODE_I NODE_I from link " " union all "
2
6437
by: tghamm | last post by:
Ok, so this is driving me mad. For some reason, regardless of the value of ev.hasmorepages, the printoducment1_printpage gets called twice for every page. So, I print 2 pages of data on one page,...
4
1509
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
2
2505
by: ccarter45 | last post by:
Help! I need to write a program that reads a text file with numbers and sums up each line of numbers. Then write a part of the program that outputs the text to another file. How do I do this? ...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7183
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7235
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1431
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.