The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
How to grep from a list
Discuss How to grep from a list in the Perl Programming forum on Dev Shed. How to grep from a list Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 5th, 2012, 02:05 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 8
Time spent in forums: 3 h 15 m 47 sec
Reputation Power: 0
|
|
|
How to grep from a list
Hi
Below is what I am trying to do. I have a variable which contains a list of commands seperated by ":". While trying to use a for loop to get each command, it doesnt retrun the correct results
Example:
var="command -1:command -2*: command something*"
for c in `echo $var | tr ':' ' '`
do
echo $c
done
Instead of getting the below
command -1
command -2*
command something
I get
command
-1
command
-2*
command
something
Please help
|

November 5th, 2012, 03:17 PM
|
|
|
|
Is this supposed to be Perl?
It looks like shell to me. But some parts are looking a bit like Perl. Don't do such things. Do it in Perl or in shell script, not a mixture of both (even though you may call some shell command from Perl if you need).
|

November 5th, 2012, 03:55 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 8
Time spent in forums: 3 h 15 m 47 sec
Reputation Power: 0
|
|
|
This is shell and I keep posting this in Perl coz I dont see a seperate section for shell scripting. I am not sure if I missed it but I did look for it
|

November 5th, 2012, 08:55 PM
|
 |
Contributing User
|
|
Join Date: Apr 2012
Location: spaceBAR Central
|
|
Try it using an array:
Code:
$ cat test.sh
var=("command -1:" "command -2*:" "command something*")
for c in "${var[@]}"
do
echo $c | sed 's/\://g'
done
$ test.sh
command -1
command -2*
command something*
|

November 5th, 2012, 09:04 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 8
Time spent in forums: 3 h 15 m 47 sec
Reputation Power: 0
|
|
|
Thanks a bunch!!!!
|

November 6th, 2012, 01:08 AM
|
|
|
Quote: | Originally Posted by Elizabeth H This is shell and I keep posting this in Perl coz I dont see a seperate section for shell scripting. I am not sure if I missed it but I did look for it |
Allright, sorry, but then, may be you should tell it upfront, because I was initially thinking: "oh, man, what a mess, she really understands nothing to Perl and thinks it is like shell." ;-)
I guess you have a solution by now.
|

November 6th, 2012, 05:35 AM
|
 |
'fie' on me, allege-dly
|
|
Join Date: Mar 2003
Location: in da kitchen ...
|
|
|
Unix Help or Linux Help is probably where it should be posted, but the description doesn't mention shell scripting
Windows Help used to have a good few WSH questions at one time, but I don't spend too much time there
__________________
--Ax
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
 
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski
Deta vil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE
|

November 7th, 2012, 06:50 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 34 m
Reputation Power: 0
|
|
|
I'm on Solaris and it is saying there is no -d option for grep.
I see what you were doing there. Nice and simple if I were on something a bit more full featured.
so close, so far away...
Thanks
|

November 7th, 2012, 12:20 PM
|
|
|
|
Maybe you have egrep installed.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|