grep search for http address in a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep search for http address in a file.
# 1  
Old 07-14-2010
grep search for http address in a file.

Hi

I have downloaded a HTM file from the web.
What I want to do is perform a grep search of that file, searching for all strings where 'http' is present within the file, but only contains the word 'cache' within the string.

I've includeda sample file, which I'm trying to extract the above result from

This is what I can think of at the moment codewise (lame I know)
grep "http" (don't know how to search for 'cache') > results.html

Thanks
C.
# 2  
Old 07-14-2010
Maybe:

Code:
[house@leonov] grep -o 'http://.*cache.*/' data.html
http://v4.lscache3.c.youtube.com/
http://v4.lscache8.c.youtube.com/
http://v14.lscache7.c.youtube.com/
http://v4.lscache3.c.youtube.com/
http://v4.lscache8.c.youtube.com/
http://v14.lscache7.c.youtube.com/

# 3  
Old 07-14-2010
i only need to capture the last instance of the HTTP addresss, that contains 'cache', is there a switch for this ?
# 4  
Old 07-14-2010
Code:
[house@leonov] grep -o 'http://.*cache.*/' data.html | tail -n 1
http://v14.lscache7.c.youtube.com/

# 5  
Old 07-15-2010
Code:
grep http youtube3.html |grep cache
awk '/http/&&/cache/' youtube3.html

Only last instance by one command:

Code:
awk '/http/&&/cache/ {a=$0}END{print a}' youtube3.html

# 6  
Old 07-26-2010
Why do I have to use 'awk' can this request not be implemented within a grep command ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -w ip address from a file isnt working need help

I have a file "file1" that contains several ip address , and the "file2" contains several records , each line in file2 contains somewhere the ip address that i am searching in the file1 I use the unix command grep -w for i in `cat file1` do grep -w "$i" file2 >> file3 done ... (9 Replies)
Discussion started by: knijjar
9 Replies

2. Shell Programming and Scripting

Search file pattern using grep command

I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing... (7 Replies)
Discussion started by: vinus
7 Replies

3. UNIX for Dummies Questions & Answers

Grep for ip address only from a file

Facing issues in grepping only the IP Address from a file i have tried the below and it was of not much help awk -F"" '/(/ { print $3 }' awk -F"</*(>" '/ip/ { print $2 }' grep "ip" file1|cut -f2 -d"<"|cut -f2 -d">" grep "(" file1 |cut -f2 -d"<"|cut -f2 -d">" grep -e... (9 Replies)
Discussion started by: satishcarya
9 Replies

4. UNIX for Dummies Questions & Answers

Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt: FT /Gene_Name="Guanyl-Acetylase 9" FT /Gene_Number"36952" FT /Gene_Name="Endoplasmic Luciferase" FT /Gene_Number"36953" FT ... (4 Replies)
Discussion started by: Twinklefingers
4 Replies

5. Shell Programming and Scripting

Grep IP address form a text file along with the subnet

I have an input file: class 1 3 5 10.10.10..0/23 hicks jimmy class 3 10.12.10.0/22 mike class.019283 10.10.15.10/20 henry gym.847585 45 192.168.10.0/22 nancy jim steve maya The output should look like this: 10.10.10..0/23 10.12.10.0/22 10.10.15.10/20 192.168.10.0/22 I have the... (3 Replies)
Discussion started by: e_mikey_2000
3 Replies

6. UNIX for Dummies Questions & Answers

Grep exact IP address from file

I have a file with a lot of IP addresses in it named "address.list". address.list looks something like this: 10.77.50.11 10.77.50.110 10.77.50.111 a bunch more addresses For every IP address I need to grep another file to see if the IP address is in the other file: for x in `cat... (5 Replies)
Discussion started by: squoggle
5 Replies

7. Shell Programming and Scripting

grep ip address from file

I have a file $ cat ip12 11.22.33.44 192.68.1.2 helo l 72.34.34.200 333.444.555.666 12.23e.544.423 myip1 11.22.33.44 myip2 33.44.55.66 #fine this IP should also be listed I do $ cat ip12 | grep '^\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}$' 11.22.33.44 192.68.1.2 (2 Replies)
Discussion started by: anil510
2 Replies

8. UNIX for Dummies Questions & Answers

awk and grep to search a data file

Hi everyone, I cannot figure out how I can do a search in a file that has Names, Surnames, Addresses and telephone number of a number of people. Here is an example of the data file Daisy:Hunter:490 London Road:07313196347 Richard:Murphy:983 Main Road:07002625997 Isobel:Magnusson:133 London... (1 Reply)
Discussion started by: philipisaia
1 Replies

9. Shell Programming and Scripting

help for search or grep in a file

i have a file like <fruits> <red>redcolor<\red> <banana>yellow color and it is<\banana> </fruits> i want to search for a word in a file data between the tags i mean searching should be done in redcolcor, yellow color and it is (2 Replies)
Discussion started by: pvr_satya
2 Replies

10. Shell Programming and Scripting

how to search -n in a file with grep

can anybody let me know how can i search for "-n" in a text file; or if my file name is "-n" (which is legal in Unix) how do i deal with that? thanks (2 Replies)
Discussion started by: lamilami
2 Replies
Login or Register to Ask a Question