- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ksh while read loop returns nothing
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 03:12 PM
01-17-2011 03:12 PM
I can cat the file in the script one step above and it returns data, on entry per line, but when I try to do a while loop, even the echo $i returns nothing.
...
cat $TICKETS_IN_AC_LOG
cat $TICKETS_IN_AC_LOG|while read i
do
echo $i
var=`grep $i $TICKETS_COMPLETE_IN_WFMS_LOG`
if [[ $var -eq 0 ]]
then
echo $i >>$TICKETS_MISMATCH
fi
done
...
Solved! Go to Solution.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 03:30 PM
01-17-2011 03:30 PM
Re: ksh while read loop returns nothing
On what?
uname -a
You might find more people who would look at
a complete (small) test script than will try
to guess exactly what you're doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 03:40 PM
01-17-2011 03:40 PM
Re: ksh while read loop returns nothing
while read i; do
echo $i
var=$(grep $i $TICKETS_COMPLETE_IN_WFMS_LOG)
if [[ $var -eq 0 ]]; then
echo $i >> $TICKETS_MISMATCH
fi
done < $TICKETS_IN_AC_LOG
That "if" is suspect. You seem to be searching a file $TICKETS_COMPLETE_IN_WFMS_LOG for a record in $TICKETS_IN_AC_LOG and then checking it for the value 0.
Did you want to check the exit status instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 03:48 PM
01-17-2011 03:48 PM
SolutionThis works for me:
...
while read i
do
echo ${i}
var=$(grep -c "$i" ${TICKETS_COMPLETE_IN_WFMS_LOG})
if [ ${var} -eq 0 ]; then
echo ${i} >> ${TICKETS_MISMATCH}
fi
done < ${TICKETS_IN_AC_LOG}
...Notice that we changed the archaic backtick syntax to the POSIX $(...) notation to run a command.
Too, the 'grep -c' returns the *count* of matched items which is then tested. You weren't doing that correctly.
Lastly, we eliminated the extraneous process --- the 'cat'. The shell can do this (as shown) much more efficiently as I wrote it.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 05:09 PM
01-17-2011 05:09 PM
Re: ksh while read loop returns nothing
if it does, put that record in $TICKETS_MISMATCH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 05:12 PM
01-17-2011 05:12 PM
Re: ksh while read loop returns nothing
while read i; do
echo $i
var=$(grep $i $TICKETS_COMPLETE_IN_WFMS_LOG)
if [[ $var -eq 0 ]]; then
echo $i >> $TICKETS_MISMATCH
fi
done < $TICKETS_IN_AC_LOG
Still wont echo line. and it returns nothing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 06:09 PM
01-17-2011 06:09 PM
Re: ksh while read loop returns nothing
cat $TICKETS_IN_AC_LOG|while read i
do
echo "$i"
done
This should list the file contents (leading spaces truncated). If that works OK, then grep:
cat $TICKETS_IN_AC_LOG|while read i
do
grep "$i" $TICKETS_COMPLETE_IN_WFMS_LOG
done
Now it is important to note that imbedded spaces and tabs (ie, white space) will NOT always compare equal. Are the strings in $TICKETS_IN_AC_LOG full of spaces? It would help by showing sample contents of both logs. I would extract 5-10 sample records from each and run grep manually until you get the desired results.
Once your grep is working, you can simplify the script to just:
cat $TICKETS_IN_AC_LOG|while read TEXT
do
[[ $(grep -c "$TEXT" $TICKETS_COMPLETE_IN_WFMS_LOG) -eq 0 ]] &&
echo "$TEXT" >> $TICKETS_MISMATCH
done
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2011 07:27 PM
01-17-2011 07:27 PM
Re: ksh while read loop returns nothing
A complete test case might change that.
Just a thought.