IFS script doesn't work

I'm parsing a file bit it's only reading the first line in the file and stops and I've no idea why
While  IFS=',' read w1 w2 w3;do
If [[ $w1== "this" ]];then
Ps -aux | grep $w3
else
If [[ $w2 == "that" ]]; then
Ps -ef | grep $w3
fi
fi
done < file


File
Ubuntu, ver 4, root
Debian, ver 3, sysadmin

In theory should this script work to output both lines in the file?
lolaferrariAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
w1 is the first word read from each line, that word is not "this" nor "that" in your sample file so your script will not do anything.

What do you want it to do?
0
Gerwin Jansen, EE MVETopic Advisor Commented:
This way it's doing something:
IFS=","
while read w1 w2 w3
do
	if [ "${w1}" == "Ubuntu" ]
	then
		ps -ef | grep ${w3}
	else
		if [ "${w2}" == "Ubuntu" ]
		then
			ps -ef | grep ${w3}
		fi
	fi
done < file

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lolaferrariAuthor Commented:
Ah sorry my sample file is a dummy - in real life they match. In debug mode it actually works and gives the output when running again the first line in the file but it doesn't run the rest.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
What if you just echo the 3 fields from the input file instead of the if statement, what do you get then?

<edit>

I mean like this:
IFS=","
while read w1 w2 w3
do
	echo "w1: ${w1}"
	echo "w2: ${w2}"
	echo "w3: ${w3}"
#	if [ "${w1}" == "Ubuntu" ]
#	then
#		ps -ef | grep ${w3}
#	else
#		if [ "${w2}" == "Ubuntu" ]
#		then
#			ps -ef | grep ${w3}
#		fi
#	fi
done < file

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.