Hello , How all doing today.. I have a little doubt in Unix
What have you done so far to resolve your "doubt"?
Just developing the thought process, can be wrong
i=0
cat file | while read line
do
a=`echo $line | cut -d':' -f1`
b=`echo $line | cut -d':' -f2`
if [ i <= 0] then
echo $a
i++
fi
if [ i >=0 ] then
Then Compare $a with 1st field of next line if same the concatenate the second field
fi
awk -F: '$1!=f1 {printf("%s%s",(FNR==1)?"":ORS,$0);f1=$1;next}{printf(" %s", $2)}END{printf ORS}' myFile
Thanks for your support. Its just an idea
Can't it be done with and array (like hashing)
I don't know what you mean, but you can definitely try.....
I took the liberty to modify your script:
#!/bin/bash
i=0
while read line
do
a=`echo $line | cut -d':' -f1`
b=`echo $line | cut -d':' -f2`
if [ -z "${p_a}" ] || [ -z "${p_b}" ]
then
printf "${a}:${b} "
elif [ "${a}" == "${p_a}" ]
then
printf "${b} "
elif [ "${a}" != "${p_a}" ]
then
printf "\n${a}:${b} "
fi
p_a=${a}
p_b=${b}
done < file