The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 02-14-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
Quote:
Originally Posted by ghostdog74 View Post
Code:
while  read -r line
do
    case $line in
        first*|second*|third* ) echo "$line";;
    esac 
done < "file"
That looks like it should work, though like I said, the grep/awk solution would be more efficient. Maybe you should put double-quotes around the $line, as in:
Code:
case "$line" in
In ksh and bash, you can also parse out the first word from the rest:
Code:
case "${line%% *}" in
   first|second|third) echo "$line";;
esac