Greping array values in Bash like Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Greping array values in Bash like Perl
# 1  
Old 08-10-2010
Greping array values in Bash like Perl

Hi,

Is there an easy way to simulate following Perl code in Bash.

Code:
 if ( grep {$my_value eq $_} @ARGV ){
       print "Do Something\n";
 } else {
            die "Invalid value";
}


Last edited by Franklin52; 08-10-2010 at 03:40 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Values rotation in array with bash

Hello :) I created a little script that allow to make a rotation of values in an array. The goal was to shift the values to the right and that the last value of the array became the first value in order to create a rotation. The purpose of the exercice was to do it without using a temporary... (6 Replies)
Discussion started by: Nexy
6 Replies

2. Shell Programming and Scripting

Values rotation in array with bash

Hello :) I created a little script that allow to make a rotation of values in an array. The goal was to shift the values to the right and that the last value of the array became the first value in order to create a rotation. The purpose of the exercice was to do it without using a temporary... (3 Replies)
Discussion started by: Nexy
3 Replies

3. UNIX for Beginners Questions & Answers

Qn on awk greping values

Hello Experts, I was trying to awk out some data out of a text file. Below is a sample file which I have xxx ***Wed Jun 28 18:00:59 CDT 2015 avg-cpu: %user %nice %system %iowait %steal %idle 17.10 0.00 4.56 2.86 0.00 75.48 Device: rrqm/s wrqm/s ... (2 Replies)
Discussion started by: DevAnand
2 Replies

4. Shell Programming and Scripting

Perl next if @array (exclude a list of values)

I'm trying to exlude a list of values with perl to process while reading in a file. Is there a way to use the next if with a list? Example: @array = qw(val1 val2 val3 val6); while (<>) { next if $_ =~ @array; # values I don't want to process here print; # process the rest here }... (8 Replies)
Discussion started by: timj123
8 Replies

5. Shell Programming and Scripting

Perl : Assigning multile hash values to a single array

I know that @food = %fruit; Works. But how do I assign %fruit and %veggies to @food ? (2 Replies)
Discussion started by: popeye
2 Replies

6. UNIX for Advanced & Expert Users

Search and replace a array values in perl

Hi, i want to search and replace array values by using perl perl -pi -e "s/${d$i]}/${b$j]}" *.xml i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.". please tell me what's wrong this line (1 Reply)
Discussion started by: arindam guha
1 Replies

7. UNIX for Dummies Questions & Answers

Passing values from file into array in Bash

Hi, I'm trying to write a bash script that takes a file and passes each line from the file into an array with elements separated by column. For example: Sample file "file1.txt": 1 name1 a first 2 name2 b second 3 name3 c third and have arrays such as: line1 = ( "1" "name1" "a"... (3 Replies)
Discussion started by: ShiGua
3 Replies

8. Shell Programming and Scripting

How to map the values of an array in perl?

Hi, I have 2 arrays: @names=qw(amith veena chaitra); @files=qw(file.txt file1.txt file3.txt); There is one to one relationship between names and files. There needs to be mapping created between names and files. The output should be like this: amith --> file.txt veena --->... (3 Replies)
Discussion started by: vanitham
3 Replies

9. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

10. Shell Programming and Scripting

perl: Assigning array values..

I have to add a variable value to an array, something like this: ...... @my_array_name = $value_of_this_variable; This doesnt seem to work, any ideas why? Thanks! (4 Replies)
Discussion started by: looza
4 Replies
Login or Register to Ask a Question
BASHBUG(1)							      bashbug								BASHBUG(1)

NAME
bashbug - report a bug in bash SYNOPSIS
bashbug [--help] [--version] [bug-report-email-addresses] DESCRIPTION
bashbug is a utility for reporting bugs in Bash to the maintainers. bashbug will start up your preferred editor with a preformatted bug report template for you to fill in. Save the file and quit the editor once you have completed the missing fields. bashbug will notify you of any problems with the report and ask for confirmation before sending it. By default the bug report is mailed to both the GNU developers and the Debian Bash maintainers. The recipients can be changed by giving a comma separated list of bug-report-email-addresses. If you invoke bashbug by accident, just quit your editor. You will always be asked for confirmation before a bug report is sent. OPTIONS
--help Show a brief usage message and exit. --version Show the version of bashbug and exit. bug-report-email-addresses Comma separated list of recipients' email addresses. By default the report is mailed to both the GNU developers and the Debian Bash maintainers. ENVIRONMENT
DEFEDITOR Editor to use for editing the bug report. EDITOR Editor to use for editing the bug report (overridden by DEFEDITOR). SEE ALSO
bash(1), reportbug(1), update-alternatives(8) for preferred editor. AUTHOR
This manual page was written by Christer Andersson <klamm@comhem.se> for the Debian project (but may be used by others). GNU Bash 3.1 11 December 2007 BASHBUG(1)