Find the answer to your Linux question:
Results 1 to 3 of 3
I'm trying to write a script which greps a file and sends each line it finds to a function. The following works fine: Code: grep REAL_TIME $file But trying to ...
  1. #1
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845

    Bash - grep to function

    I'm trying to write a script which greps a file and sends each line it finds to a function. The following works fine:

    Code:
    grep REAL_TIME $file
    But trying to output the results to a function (my_function) using any of the following doesn't work.

    Code:
    grep REAL_TIME $file >> my_function
    grep REAL_TIME $file &> my_function
    grep REAL_TIME $file | my_function
    Any ideas?

  2. #2
    Linux User
    Join Date
    Jun 2007
    Posts
    318
    How about this:

    Code:
    grep REAL_TIME $file > tmp.tmp
    while read lne
        do
            my_function "$lne"
        done < tmp.tmp
    rm -f tmp.tmp

  3. #3
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Perfect. Thank you

Posting Permissions

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