Skip to main content
added 450 characters in body
Source Link
cas
  • 84.3k
  • 9
  • 136
  • 205

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | sed -nE "s/$re/\1 \2/p")

I'm not entirely sure that I trust that, though - it's far too easy for whatever is in $re to break the sed script. It would be better to pass $re to awk via awk's -v option or to either awk or perl as an exported environment variable.

e.g.

export re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | perl -n -e 'print "$1 $2\n" if m/$ENV{re}/')

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | sed -nE "s/$re/\1 \2/p")

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | sed -nE "s/$re/\1 \2/p")

I'm not entirely sure that I trust that, though - it's far too easy for whatever is in $re to break the sed script. It would be better to pass $re to awk via awk's -v option or to either awk or perl as an exported environment variable.

e.g.

export re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | perl -n -e 'print "$1 $2\n" if m/$ENV{re}/')

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

deleted 2 characters in body
Source Link
cas
  • 84.3k
  • 9
  • 136
  • 205

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A |
           sed -nE 's"s/([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.$re/\1 \2/p'p")

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A |
           sed -nE 's/([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\./\1 \2/p')

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

re='([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\.'
while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A | sed -nE "s/$re/\1 \2/p")

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

Post Undeleted by cas
replaced xargs with a while-read loop
Source Link
cas
  • 84.3k
  • 9
  • 136
  • 205

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do it something like this:

while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A |
           sed -nE 's/([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\./\1 \2/p' |
  xargs -n 2 FUNCTION_B)

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do it something like this:

FUNCTION_A |
  sed -nE 's/([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\./\1 \2/p' |
  xargs -n 2 FUNCTION_B

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

I wouldn't write this in bash or any dialect of sh (for the reasons already mentioned in comments), but it seems like you're trying to extract numeric values from the output of one function and pass them two at a time to a second function?

If that's correct, you could do something like this:

while read -r a b ; do
  FUNCTION_B "$a" "$b"
done < <(FUNCTION_A |
           sed -nE 's/([0-9-]+\.[0-9-]+).*Peak usage: ([0-9-]+) megabytes\./\1 \2/p')

However, I strongly recommend you put some time into learning awk and/or perl. sed and grep too.

Post Deleted by cas
Source Link
cas
  • 84.3k
  • 9
  • 136
  • 205
Loading