473,624 Members | 1,993 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 8989
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_200 0k.txt"

What I would like to do is grep the entire web site using each line from "files_over_200 0k.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.t xt"
Apr 6 '09 #7

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

Similar topics

3
13785
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 named textOrigin.txt in which I store the text to search in. I would like my prog to check if a certain word appears in the text and than to tell me what line it found it in (if it did...). My problem is that the script can't find the words I'm...
6
2650
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 14 09/04/2004 LSU 22 Oregon State 21 09/09/2004 Troy State 24 Missouri 14 As you can see, the text file contains a list of games. Each game has a date, a winning team, the winning...
2
1980
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
7380
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 file. At the end of each record I insert a vbCrLf character in the text file to create a new line. Thus each record is in a new line. The problem is that I get a tab delimited text file where the LAST LINE in the text file is always a blank line....
5
15167
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
6449
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, with the second overlaying the original data. If i set ev.hasmorepages to false, essentially telling the printdocument to only print one page, it prints one page, with two pages of data, because at the end of the _printpage subroutine, even...
4
1525
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
2514
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? Here's what the data file looks like: 1 2 2 3 3 4 4 5 5 6 Here is the code I have: import java.util.Scanner;
0
8236
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8679
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8475
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
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 we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.