I am working with a pipe separated list(text file), which looks like
recipename|category|list_items
-------------------------------------------
veg_quesadilla|groupA|lettuce, spinach, beans
burrito_bowl|groupA|brown_rice, black_beans, lettuce, pepper
french_fries|groupB
beverage|groupC|pepsi
I have below statement
for recipename in `head -4 list_catalog.txt | awk -F "|" '{print $1}'`
do
if [ `cat list_catalog.txt | grep $recipename | awk -F "|" '{print $3}'` != NULL ]
then
for list_items in `cat list_catalog.txt | grep $recipename | awk -F "|" '{print $3}'`
do
echo -e ${list_items}
done
fi
done
In the first loop, i am iterating over each recipe name, and i am checking if the list_items exists for each recipe. If yes, then i want to print all the column seperated items as one string, instead of seperated items. I mean all the comma separated items (which starts after second pipe symbol) as one string
Like this:
lettuce, spinach, beans
Instead of:
lettuce,
spinach,
beans
And when i run the code i am getting error,
line 3: [: too many arguments
Not sure, if i am doing right with AWK or not. Please correct me.