Help with simple Shell Script

Hi ,

I am in need of simple shell script that has one input file containing some words

Input file 1 :

****ALEX***JOHN*******VIRGIL*****
CHRITINE*****FAISAL*****DON*****
****ALEX***JOHN*******VIRGIL*****
CHRITINE*****FAISAL*****DON*****
****ALEX***JOHN*******VIRGIL*****
****ALEX***JOHN*******VIRGIL*****
CHRITINE*****FAISAL*****DON*****
****ALEX***JOHN*******VIRGIL*****
CHRITINE*****FAISAL*****DON*****
****ALEX***JOHN*******ALEX*****

Input file 2 : (Needs to be created at run with below text)

ALEX
CHRISTINE
DON
FAISAL
JOHN
VIRGIL

Output file 3 : (Needs to be created at run time of Shell with the count of words in Input file 1)

ALEX             = 7
CHRISTINE   = 4
DON              =  4
FAISAL         =  4
JOHN            =  6
VIRGIL          =  5
ANDREW      = 0

Please let me know your thoughts/ suggestions on this. Thanks in advance.!!

Where is the script you need help on?

#!/bin/sh

# By using [*]+ as field separator, strip them all out and
# get them as sane tokens.
# By using OFS="\n", print one name per line.
# ORS="" prevents a few extra newlines.
# $1=$1 is necessary to actually transform the data, which isn't otherwise modified.
file1 < awk -v FS="[*]+" -v OFS="\n" -v ORS="" '{ $1=$1 ; NF--; } 1' |
# Sort alphabetically
        sort | 
# Count repetitions, save output to temp file.
        uniq -c > /tmp/$$

# Read the sorted file, and output it in the manner we need.
while read COUNT NAME
do
        # Ignore blank first line
        [ -z "$NAME" ] && continue
        echo "$NAME = $COUNT"
        echo "$NAME" >&2
done < /tmp/$$ > file2 2> file3

# delete temp file.
rm -f /tmp/$$

Typo in the redirection: > file1

Regards,
Alister

Thanks Corona..but needs some more understanding..could you please..?

I already commented everything profusely and don't know what else to explain, if you have more specific questions I'd be happy to answer them.

---------- Post updated at 04:45 PM ---------- Previous update was at 04:43 PM ----------

I don't think it's a typo, given I want to read from file1 and not write to it...

It is, but so was mine. :wink: I meant "< file1" instead of "> file1".

Your script will try to run a command named "file1" with standard input redirected from a file named "awk". The operator needs to precede the filename.

Regards,
Alister