I would address your second problem first. This little/simple script would do your job nicely. Its simple, so you can enhance it as per your need
#!/bin/ksh
count=1
echo "UNPurchased Items"
echo
for name in `grep "\-$" tmp11 | awk -F"|" '{print $1}'`
do
echo "$count. $name"
count=`expr $count + 1`
done
count=1
echo
echo "Purchased Items"
echo
for name in `grep -v "\-$" tmp11 | awk -F"|" '{print $1}'`
do
echo "$count. $name"
count=`expr $count + 1`
done
NOTE: this is the KSH version, if you are a perl guy then you must be knowing ( may be not able to recollect on the top of your head ) that you have the env variable "$." that contains the line number of the input file being read.....just a hint.
Now your first problem. I don't know what prompted you to use those " ' " ( single quotes) in grep.
I don't have a linux box here, i tried on a Sun Box.
cat /etc/passwd | grep ` who am i |awk -F " | " '{ print $1 }'` | cut ------
( you can specify the arguments in 'cut' according to the format of etc/passwd on your machine )
I hope it helps
----------------------------------------------------------------------
I hope somebody could help me with a couple of things...
First, I would like to search the /etc/passwd file for the full name of a user given his/her username. i've tried the following command:
cat etc/passwd | grep -w '`whoami`' | cut -f 5 -d ':'
of course that didn't work as grep interprets whoami as a string, not as a command becuase of the ' '.
So does anyone know how i can get over this problem?
Second, i have a text file that contains a names of items, the price, and the date it was purchased. The content looks something like this:
t-shirt|20|-
socks|10|2004-12-10
shoes|40|2004-12-10
the item name, price and date are separated by '|' and the '-' denotes that the item wasnt purchased yet
So what i need to do here is to echo the unpurchased items and then the purchased items, i used grep to do this and it worked.
But to add, what i needed was to add a number before each item as it is displayed on the screen, something like this:
UNpurchased items:
1. tshirt 20
purchased items:
1. socks 10
2. shoes 40
they also need to be aligned as shown, can anyone show me how to do this? Help would be very mush appreciated.
Sincerely,
marco83