CentOS 5.x
I'm trying to build a shell script that searches data provided via stdin. Here's an example of the input stream:
Date: 1/1/11
Time: 12:00 AM
Foo: 12345
Foo1: dskjflsdkjflksdjlfds
Foo2: 123456789
Foo3: kdsjflskdjflkjsdlkfjsdlkjflksdjflkjsdklfjlksdjflk
This information doesn't exist in a file, it would only be sent to the script in real-time as stdout from another app.
I want the sript to look at the data and parse out the values for Foo: and Foo2: storing those as variables for use later in the script.
My revised script attempt is this:
#!/bin/bash
while read data; do
SearchCriteria1=$(echo "$data" | grep "Foo: " | cut -c 5-)
SearchCriteria2=$(echo "$data" | grep "Foo2: " | cut -c 6-)
echo $SearchCriteria1 >> test.1
echo $SearchCriteria2 >> test.2
done
The finished script won't actually use test.1 or test 2 files. I just have them listed here for easier examples.
In this example, I would expect test.1 to have:
12345
In this example, I would expect test.2 to have:
123456789
When I test this though, both test.1 and test.2 are blank and I know the data has the valid info in it.
I'm missing something obvious. Can someone please clarify?