[CentOS] Need help in writing a shell/bash script

Fri Dec 30 16:50:30 UTC 2011
Craig White <craig.white at ttiltd.com>

looked like English to me...

On Dec 30, 2011, at 9:41 AM, m.roth at 5-cent.us wrote:

> Hey, supergiantpotato (and btw, this list is plain text, not unicode, and
> most of us don't read Japanese...),
> 
> 夜神 岩男 wrote:
>> On 12/30/2011 09:00 PM, ankush grover wrote:
>>> 
>>> I am trying to write a shell script which can merge the 2 columns into
>>> 3rd one on Centos 5. The file is very long around 31200 rows having
>>> around 1370 unique groups and around 12000 unique user-names.
>>> The 1st column is the groupname and then 2nd column is the user-name.
>>> 
>>> 1st Column (Groupname)            2nd Column (username)
>>>                 admin                      ankush
>>>                 admin                       amit
>>>                 powerusers               dinesh
>>>                 powerusers               jitendra
> <snip>
>> This will do what you want. But please read the comments in the code.
> <snip>
>> #######BEGIN collator.sh
> <snip>
>> INFILE=${1:?"Input filename missing, please read script comments."}
>> OUTFILE=${2:?"Output filename missing, please read script comments."}
>> 
>> awk '{print $1 ": "}' $INFILE | uniq > $OUTFILE
>> for GROUP in `cat $OUTFILE | cut -d ':' -f 1`
>>     do for NAME in `cat $INFILE | grep $GROUP | awk '{print $2}'`
>>         do sed -i "s/^$GROUP: /&$NAME,\ /" $OUTFILE
>>     done
>> done
>> #######END collator.sh
> 
> This is really complicated and fiddly. Look at the one awk script that was
> posted, which is *far* simpler, and uses awk the way it's intended to be
> used, not as a replacement for cut....
> 
>       mark
> 
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos

-- 
Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.white at ttiltd.com
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com 

Need help communicating between generations at work to achieve your desired success? Let us help!