Regular Expressions as command line paramteters


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Regular Expressions as command line paramteters
# 1  
Old 08-01-2009
Regular Expressions as command line paramteters

Use and complete the template provided. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
We have to write a program that uses wget to get pages of a URL and search them for a pattern.

the command for the script should will look like this
> Look4Pattern URL E [L]
URL - url to search
E - string or regular expression to search for (10pts more for regular expression)
L - if not given then search only root level, otherwise recursively search L levels.


3. The attempts at a solution (include all code and scripts):

I have it working fine except when entering a regular expression, if the bar "|" is used, it is interpreted as a pipe instead of an argument, thus if I enter
Look4Pattern Yahoo! grey|gray 1
I would get an error message
bash: gray: command not found

is there anyway to get around this other than make the user enter regular expressions in quotation marks?


4. School (University) and Course Number:
# 2  
Old 08-01-2009
you use the "|" as a pipe in your command. but without seeing the whole code we can't help you further...
# 3  
Old 08-01-2009
You have to keep the shell from parsing the pipe symbol:
Code:
$ echo grey|gray
bash: gray: command not found
$ echo 'grey|gray'
grey|gray

# 4  
Old 08-01-2009
Sorry,
I did not think the code was relevant. Thank you for taking the time to help me.

Code:
#! /bin/bash
mkdir wGetResults
cd wGetResults
cWd1=`pwd`
if test "$#" = 2
then
    tryCmd="wget "$1
fi
if test "$#" = 3
then
    tryCmd="wget -r -l"$3" "$1
fi
gRepper="egrep -r -l -e "$2" "$cWd1"/"
$tryCmd
$gRepper

# 5  
Old 08-01-2009
how do you call the script? give an example with the output...

Last edited by DukeNuke2; 08-01-2009 at 05:46 PM..
# 6  
Old 08-01-2009
Thank you for all of your help, I think pludi answered my question.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions

I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav' I want to move the characters beginning with - end before. I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies

2. UNIX for Advanced & Expert Users

What is the difference between single line mode and multiline mode in Regular expressions?

Hi All, Can please let me know what is the difference between the single line mode and multi line mode in regular expresions? Thanks, Chidhambaram B (3 Replies)
Discussion started by: chidhu.anu
3 Replies

3. Shell Programming and Scripting

Regular Expressions

Hi Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies

4. Homework & Coursework Questions

Regular expressions output is whole line

Hi, I am newbie in shell programming and I need some help. I had some data and I format it in a file like dn: uid=aaaaa, dc=exmple, dc=com cn: bbbb cccc sn: cccc telephoneNumber:+30-6543-123456 I have to extract the information aaaaa , bbbb, cccc and the phone number using awk... (3 Replies)
Discussion started by: pro
3 Replies

5. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

6. Shell Programming and Scripting

How to grep using a line break in regular expressions?

Hi, I have a file as below, {#### if file then file else file } print file i need to fine the count of all the pattern - file, inside the { } i'm using a grep command as grep -c \{'*file*'\} fake.sh\ It doesn't gives me any result, i think the problem here is the... (5 Replies)
Discussion started by: divak
5 Replies

7. UNIX for Advanced & Expert Users

Regular Expressions

Hi, below is a piece of code written by my predecessor at work. I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code. It is really a tough time for me to figure out all the regular expressions. Please shed some light on the regular expressions... (3 Replies)
Discussion started by: ramky79
3 Replies

8. Shell Programming and Scripting

regular expressions

Hi, can anyone advise me how to shorten this: if || ; then I tried but it dosent seem to work, whats the correct way. Cheers (4 Replies)
Discussion started by: jack1981
4 Replies

9. Shell Programming and Scripting

Regular Expressions

How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length? Eg: Input File san.txt hello hi ... (6 Replies)
Discussion started by: sandeep_hi
6 Replies

10. Programming

regular expressions in c++

How do I use the regular expressions in c++? (2 Replies)
Discussion started by: szzz
2 Replies
Login or Register to Ask a Question