I am having a File format as mentioned below
Quote:
Employee id|Name|Languages
12345|ABC|02|English|Hindi
4567|DEF|03|Engligh|Hindi|Urdu
the 02 and 03 are counters. Using that we need to generate the output records as mentioned below
12345|ABC|English
12345|ABC|Hindi
4567|DEF|English
4567|DEF|Hindi
4567|DEF|Urdu
Below is the code to handle above scenario
Code:
while read line
do
emp_id=`echo $line | awk -F'|' '{print $1}'`
name=`echo $line | awk -F'|' '{print $2}'`
counter=`echo $line | awk -F'|' '{print $3}'`
counter1=4
while [[ $counter -gt 0 ]]
do
language=`echo $line |cut -f$counter1 -d"|"`
counter1=`expr $counter1 + 1`
counter=`expr $counter - 1`
echo $emp_id'|'$name'|'$language>>output.txt
done
done <input.txt