473,378 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

16
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 8966
gpraghuram
1,275 Expert 1GB
You want to embedd the whole logic in a AWK program? or whats ur requirement?

raghu
Apr 3 '09 #2
kronus
16
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 Expert 256MB
use the -f option of grep, eg
Expand|Select|Wrap|Line Numbers
  1. grep -f file1 file2
  2.  
Apr 4 '09 #4
ghostdog74
511 Expert 256MB
use the -f option of grep, eg
Expand|Select|Wrap|Line Numbers
  1. grep -f file1 file2
  2.  
Apr 4 '09 #5
kronus
16
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
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
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
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
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
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
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
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
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
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
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.