find words with grep....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find words with grep....
# 1  
Old 04-06-2006
find words with grep....

I have a .txt file which contains several lines of text. I need to write a script program using grep or any other unix tool so as to detect part of the text (words) between / / that begin with the symbol ~.
For example if somewhere in the text appears a webpage address like
http://www.cs.may.ie/~dtray/cs211/lecture1.htm,
my program must print only the word dtray (the symbol ~ must be ommited)
# 2  
Old 04-06-2006
Is this a homework assignment?
# 3  
Old 04-06-2006
I would grep lines containing the keywords, and pipe to a cut.
# 4  
Old 04-06-2006
Quote:
Originally Posted by DrRo183
I would grep lines containing the keywords, and pipe to a cut.
care to provide an example?
# 5  
Old 04-06-2006
well...what are the rules/conditions? Will every url be complete as submitted above?
# 6  
Old 04-06-2006
Quote:
Originally Posted by DrRo183
well...what are the rules/conditions? Will every url be complete as submitted above?
well..... that I don't know - we better ask the OP.

but how about these simple samples:
Code:
http://www.cs.may.ie/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/foo/bar/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/foo/~bar/~dtray/cs211/lecture1.htm
http://www.cs.may.ie/~foo~dtray/cs211/lecture1.htm

how would you do it with grep/cut?
# 7  
Old 04-06-2006
"http://www.cs.may.ie/~foo~dtray/cs211/lecture1.htm" <==what?

Ok, I give up. How to differentiate whether you want the first tilde, or the nth.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep only words containing specific string

Hello, I have two files. All urls are space seperated. source http://xx.yy.zz http://df.ss.sd.xz http://09.09.090.01 http://11.22.33 http://canada.xx.yy http://01.02.03.04 http://33.44.55 http://98.87.76.65 http://russia.xx.zz http://aa.tt.xx.zz http://1w.2e.3r.4t http://china.rr.tt ... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

How to grep the words with space between?

see I have a text like: 27-MAY 14:00 4 aaa 5.30 0.01 27-MAY 14:00 3 aaa 0.85 0.00 27-MAY 14:00 2 aaa 1.09 0.00 27-MAY 14:00 5 aaa 0.03 0.00 27-MAY 14:00... (3 Replies)
Discussion started by: netbanker
3 Replies

3. UNIX for Dummies Questions & Answers

Grep words with X doubles only

Hi! I'm trying to figure out how to find words with X number of doubles, only. I'm searching a dictionary, (one word per line). For instance, if you want to find words containing only one pair of double letters, you could do something like this: egrep '(.)\1' wordlist.txt |egrep -v '(.)\1.*(.)\2'... (3 Replies)
Discussion started by: sudon't
3 Replies

4. Shell Programming and Scripting

Confused with grep for multiple words

Hi guys and gals, I have many files that contains many lines of data. I am trying to find a needle in a haystack in that I'm looking only for files that contain word1 AND word2. I'm using ... ... but this is finding files that contains word1 OR word2. No good for me. How can I grep to... (7 Replies)
Discussion started by: bbbngowc
7 Replies

5. Shell Programming and Scripting

grep words from txt

Queue on node in domain description : type : local max message len : 104857600 max queue depth : 5000 queue depth max event : enabled persistent msgs : yes backout threshold : 0 msg delivery seq :... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

6. Shell Programming and Scripting

grep for words in file

Hi Please can you help me on this: How to grep for multiple words in a file, BUT for every word found output it to a new line. regards FR (8 Replies)
Discussion started by: fretagi
8 Replies

7. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

8. UNIX for Dummies Questions & Answers

search multiple words using grep

Hi frnds i want to desplay file names that should be word1 and word2 ex : i have 10 *.log files 5 files having word1 and word2 5 files having only word1, i have used below command egrep -l 'word1|word2' *.log its giving all 10 files, but i want to display only 5... (20 Replies)
Discussion started by: pb18798
20 Replies

9. UNIX for Dummies Questions & Answers

Grep Three Words

I have been trying to find files containing the words AAA, BBB and CCC. I tried: grep AAA `grep BBB files*` grep CCC files* but is does not work I tried several ways this is an easy one but I am a dummy, Does anyone can help me? Thanks :( (12 Replies)
Discussion started by: murbina
12 Replies

10. UNIX for Dummies Questions & Answers

grep with find to search for matchiing words

Hi all, Please help me in the following dbt i want to know the different files in the current and the sub directory which have some search key in that . for example i want to know all filenames followed by the word 'unix' in all files. the file name and the matching word have... (1 Reply)
Discussion started by: akhil313
1 Replies
Login or Register to Ask a Question