Link to home
Start Free TrialLog in
Avatar of itsme_asif
itsme_asif

asked on

Shell Script to loop through a file

Hi Experts,
 Have a dumb question, i have the following script which loops through a file and takes the word in each line of that file and does a grep on a different file, however instead of grep'ing through every single line it only gives the grep output of the last line.
#!/usr/bin/sh
 
 
# Loop through the file
for i in `cat inp.txt`
do
 
 
echo $i
grep $i it_privilege-export.csv|awk -F "," '{print $1}'
done 
 
 
 
exit 0;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itsme_asif
itsme_asif

ASKER

Hi , I figured its due to the presence of trailing space in my inp file, i removed using a sed command and things are fine now, thanks for the one liner, thats pretty usefull.