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
Gtk2::PageSetup(3pm)					User Contributed Perl Documentation				      Gtk2::PageSetup(3pm)

NAME
Gtk2::PageSetup - wrapper for GtkPageSetup HIERARCHY
Glib::Object +----Gtk2::PageSetup METHODS
pagesetup = Gtk2::PageSetup->new pagesetup = Gtk2::PageSetup->new_from_file ($file_name) o $file_name (localized file name) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 pagesetup = Gtk2::PageSetup->new_from_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 double = $setup->get_bottom_margin ($unit) o $unit (Gtk2::Unit) $setup->set_bottom_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) double = $setup->get_left_margin ($unit) o $unit (Gtk2::Unit) $setup->set_left_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) $setup->load_file ($file_name) o $file_name (string) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.14 $setup->load_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.14 pageorientation = $setup->get_orientation $setup->set_orientation ($orientation) o $orientation (Gtk2::PageOrientation) double = $setup->get_page_height ($unit) o $unit (Gtk2::Unit) double = $setup->get_page_width ($unit) o $unit (Gtk2::Unit) double = $setup->get_paper_height ($unit) o $unit (Gtk2::Unit) $setup->set_paper_size_and_default_margins ($size) o $size (Gtk2::PaperSize) papersize = $setup->get_paper_size $setup->set_paper_size ($size) o $size (Gtk2::PaperSize) double = $setup->get_paper_width ($unit) o $unit (Gtk2::Unit) double = $setup->get_right_margin ($unit) o $unit (Gtk2::Unit) $setup->set_right_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) $setup->to_file ($file_name) o $file_name (localized file name) May croak with a Glib::Error in $@ on failure. Since: gtk+ 2.12 $setup->to_key_file ($key_file, $group_name) o $key_file (Glib::KeyFile) o $group_name (string or undef) Since: gtk+ 2.12 double = $setup->get_top_margin ($unit) o $unit (Gtk2::Unit) $setup->set_top_margin ($margin, $unit) o $margin (double) o $unit (Gtk2::Unit) ENUMS AND FLAGS
enum Gtk2::PageOrientation o 'portrait' / 'GTK_PAGE_ORIENTATION_PORTRAIT' o 'landscape' / 'GTK_PAGE_ORIENTATION_LANDSCAPE' o 'reverse-portrait' / 'GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT' o 'reverse-landscape' / 'GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE' enum Gtk2::Unit o 'pixel' / 'GTK_UNIT_PIXEL' o 'points' / 'GTK_UNIT_POINTS' o 'inch' / 'GTK_UNIT_INCH' o 'mm' / 'GTK_UNIT_MM' SEE ALSO
Gtk2, Glib::Object COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice. perl v5.14.2 2012-05-27 Gtk2::PageSetup(3pm)