Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Perl to bash
Results 1 to 8 of 8

Thread: Perl to bash

  1. #1

    Perl to bash

    I've written a perl script but I think it would work better if I converted it to bash and ran it that way.
    In perl I have something like:

    open (DATA,"$path/$in"
    @data = <DATA>;
    close DATA;

    foreach $line (@data){
    print `rioutil -a $line`;
    }

    The idea is to open a file and execute the command for each line in the file.

    I can't find out how to open the file in bash or to seperate out the lines.

    Could someone give me a pointer?

    Dizzy

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Perl to bash

    You're looking for something like this:
    Code:
    #!/bin/sh
    if [ x$1 = x ]; then
        echo "Usage: $0 file1 [file2 file3 ...]"
        exit 1;
    fi
    while [ x$1 != x ]; do 
        for LINE in `cat $1`; do
            rioutil -a $LINE
        done
        shift
    done

  3. #3

    Re:Perl to bash

    [quote author=redhead link=board=9;threadid=3769;start=0#38031 date=1024062204]
    You're looking for something like this:
    Code:
    #!/bin/sh
    if [ x$1 = x ]; then
        echo "Usage: $0 file1 [file2 file3 ...]"
        exit 1;
    fi
    while [ x$1 != x ]; do 
        for LINE in `cat $1`; do
            rioutil -a $LINE
        done
        shift
    done
    [/quote]

    Let me see if I understand this right.

    The if statement is to check if $1 exists and exits if it doesn't.
    for LINE in `cat $1` reads the file $1 line by line and produces the output for each line.

    Is that right? If so is the while loop necessary?

    Dizzy

  4. #4
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Perl to bash

    [quote author=Dizzybacon link=board=9;threadid=3769;start=0#38036 date=1024063386]
    [quote author=redhead link=board=9;threadid=3769;start=0#38031 date=1024062204]
    You're looking for something like this:
    Code:
    #!/bin/sh
    if [ x$1 = x ]; then
        echo "Usage: $0 file1 [file2 file3 ...]"
        exit 1;
    fi
    while [ x$1 != x ]; do 
        for LINE in `cat $1`; do
            rioutil -a $LINE
        done
        shift
    done
    [/quote]

    Let me see if I understand this right.

    The if statement is to check if $1 exists and exits if it doesn't.
    for LINE in `cat $1` reads the file $1 line by line and produces the output for each line.

    Is that right? If so is the while loop necessary?

    Dizzy
    [/quote]
    The if [] test to see that there atleast is one argument given, ie the file in question, the while [] will run through every argument given, assuming each one is a file, and the for LINE in `cat..` will execute the command on every line found in the files. Thats basicaly it.

  5. #5

    Re:Perl to bash

    [quote author=Dizzybacon link=board=9;threadid=3769;start=0#38027 date=1024060748]open (DATA,"$path/$in"
    @data = <DATA>;
    close DATA;

    foreach $line (@data){
    print `rioutil -a $line`;
    }[/quote]

    Code:
    open (DATA, "$path/$in");
    while (<DATA>)
    {
      print `rioutil -a $_`;
    }
    close DATA;

  6. #6

    Re:Perl to bash

    Thanks redhead,

    I won't be using more than one argument, so I won't need the while 'while' but I think the other stuff is perfect.

    Dizzy

  7. #7

    Re:Perl to bash

    what about xargs?

  8. #8
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re:Perl to bash

    [quote author=njcajun link=board=9;threadid=3769;start=0#38855 date=1024709348]
    what about xargs?
    [/quote]
    So you're thinking something like:
    Code:
    cat the_file | xargs -n1 -p rioutil -a

Similar Threads

  1. cd in bash from perl
    By Blaqb0x in forum Linux - Software, Applications & Programming
    Replies: 7
    Last Post: 03-01-2004, 08:45 PM
  2. perl question from a perl newb
    By tolstoy in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 09-06-2002, 01:16 AM
  3. Bash colo(u)rs
    By airhead in forum Linux - Software, Applications & Programming
    Replies: 2
    Last Post: 06-24-2002, 09:08 PM
  4. sh vs bash.. what is different?
    By morphman in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 06-11-2002, 06:26 PM
  5. Bash PET
    By civ1492 in forum Linux - General Topics
    Replies: 9
    Last Post: 05-14-2002, 12:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •