INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

For i in $userarray[@] is one line off

For i in $userarray[@] is one line off

(OP)
Hello,
I have searched the forum, but am unable to find direction on my issue.

I have s simple BASH script below

CODE --> bash

#!/bin/bash
#
###########################
userarray=$(cat test|awk 'BEGIN {FS="\t"}; {print $1}'|sort -u)
echo "USERID              #of occurances"
for  i in $userarray[@]
do
printf "%s\t%s" "$i";grep -c $i test
done 

This script cat's a file called test, pulls out the first field and pipes to sort -u so that only unigue userid show up. I then take that into a for loop, to execute a grep -c, so that I may know how many times a userid is in the file 'test'

Here is where the trouble comes in. The last userid has [@] attached as if it is part of the username and therefore finds no userid info the the file "test" Below is the output. (note the final userid is xr400709[@] and fouond "0" times
USERID #of occurances
#####################################
automated_account 6
ax435515 1
dq325123 3
dr343023 1
hk315305 15
jv806141 7
ke277981 2
mda3992 150
me062855 2
mshrestha 7
mt480449 5
ob717914 1
oh106034 1
ol620003 12
pk694319 26
qz800289 4
sh256270 2
uno1964 20
uno403b 3
uno995b 5
user_id 1
vi251929 1
wjc4842 87
xr400709[@] 0

Sorry for the lengthy post, thanks in advance for your help.

RE: For i in $userarray[@] is one line off


Remove the "[@]" from "for i in $userarray[@]", it's not necessary.
banghead

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

RE: For i in $userarray[@] is one line off

(OP)
Thanks LK, thought I needed that.....
the EMOTICON made me laugh out loud.thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close