Sponsored Content
Full Discussion: grep a variable
Top Forums Shell Programming and Scripting grep a variable Post 302242374 by sgstuart on Wednesday 1st of October 2008 08:37:33 PM
Old 10-01-2008
while loop is all I need now

Hi all,
now all I need is to make my while loop to work, which might be syntax.

So I have

i=1
while[-n `diskutil list | grep disk1s"$i"s2 | awk '{print$3}' ]; do
echo `diskutil list | grep disk1s"$i"s2 | awk '{print$3 " " $4}'
i+=1
done

If I remove the while loop portion just keeping the i= and the echo line it works perfectly, If I make the i=2 and so forth it works perfectly, so I know that my while loop is not correct.

Thanks,
Steven Stuart
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to grep a variable?

Hi, I'd like to grep a variable that I saved in the program. Like grep '0\$variable1' file1 Does someone know what's wrong with this command? Thanks a lot! (2 Replies)
Discussion started by: whatisthis
2 Replies

2. Shell Programming and Scripting

grep with variable

Hi, I can't get this script to work (returns 0, should return 3): $ cat A.lst | \ while read LINE do echo "$LINE" grep -c "$LINE" B.tmp done> > > > > Socket 0 $ but in contrast this one works fine (returns 3 as expected): $ LINE=Socket $ grep -c $LINE B.tmp 3 $ (5 Replies)
Discussion started by: ozvena
5 Replies

3. Shell Programming and Scripting

grep a variable

can i grep a variable say i have a variable var=`hostname` and I want to make an if statement like if grep "esp-ueh" $var;then...... how can i do this I dont want to store this variable in a file and the grep it because my script will be used at the same time on multiple stations and then that... (9 Replies)
Discussion started by: lassimanji
9 Replies

4. Shell Programming and Scripting

grep using variable

how can I use grep with a variable to find a value? cat data.out Hello World grep "Hello World" data.out Hello World ## Value found I want to do something like this but can't seem to get it to work any suggestions would be appreciated. var="Hello World" grep $var data.out (3 Replies)
Discussion started by: BeefStu
3 Replies

5. Shell Programming and Scripting

Grep through a variable

I want to search a text in file but that file is pointing to variable. ex: file=there was nothing special grep "there was nothing" $file but its not working . Can u let me know that how we can use variable($file) in grep command. Please use code tags (6 Replies)
Discussion started by: allthanksquery
6 Replies

6. Shell Programming and Scripting

grep using variable

I have a pattern like: column "5" is missing PS: the no is in double quotes. The number usally changes, so we use a loop to grep. grep 'column "$number" is missing' filename.txt But it is not working.... How to solve this? (2 Replies)
Discussion started by: karumudi7
2 Replies

7. Shell Programming and Scripting

grep in a variable

Hello, I usually search extensively and have to date found what I've needed. However, this one's got me stumped. I need to create a variable as follow. The issue however is that upon execution, it freezes. $var1 isn't always present in usage.log and this is fine but I'd like it to continue with... (6 Replies)
Discussion started by: shadyuk
6 Replies

8. Shell Programming and Scripting

grep variable

I've got a file that I'm trying to grep through that looks like this: alpha1 alpha2 alpha3 beta1 beta2 gamma5 gamma6 gamma7 gamma8 gamma9 and I want the output to only contain the line with the highest value for each, so the output I want is: alpha3 beta2 gamma9 I also need... (11 Replies)
Discussion started by: tiberione
11 Replies

9. Shell Programming and Scripting

Help grep one variable over other

Hi, I am trying to grep one variable over the other variable Example: i=abc j=ab grep $j $i I am getting this error: The error is due to $i being variable and not file. I know I could do it by putting the value of abc in a file and then greping it. (1 Reply)
Discussion started by: pinnacle
1 Replies

10. UNIX for Beginners Questions & Answers

How to use $variable in grep?

hi i have a file which contains some messages counters. below is the snippet on the file. 17-05-29::22:36:21|message|231 17-05-29::22:36:31|message|222 17-05-29::22:36:41|message|213 17-05-30::22:36:51|message|221 17-05-30::22:37:01|message|227 17-05-30::22:37:11|message|207... (5 Replies)
Discussion started by: scriptor
5 Replies
Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap(User Contributed Perl DocumentPerl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap(3pm)

NAME
Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap - Don't use "map" in void contexts. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
"map" and "grep" are intended to be pure functions, not mutators. If you want to iterate with side-effects, then you should use a proper "for" or "foreach" loop. grep{ print frobulate($_) } @list; #not ok print map{ frobulate($_) } @list; #ok grep{ $_ = lc $_ } @list; #not ok for( @list ){ $_ = lc $_ }; #ok map{ push @frobbed, frobulate($_) } @list; #not ok @frobbed = map { frobulate($_) } @list; #ok CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-07 Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap(3pm)
All times are GMT -4. The time now is 09:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy