Link to home
Start Free TrialLog in
Avatar of FirstMan
FirstMan

asked on

script help for usename

Hi,

I wonder if you can have some help with a problem that i have been strugging with for some time. I want to write a simple shell script (called user) with an argument being a new created file (e.g. newfile). The script should find occurrence of the current users (e.g Richard.Jones), take that line and place it in the new created file (user) display a line number with bracket.

I have tried it using the following code with success

env | grep $USER

env | awk -v user="$USER" '$0~user{ print c++")",$0}'

But I was planning to write the script without the use of SED or AWk and i'm having abit difficulty doing so.

Help anyone???
Avatar of ozo
ozo
Flag of United States of America image

I wonder if you can have some help with a problem that i have been strugging with for some time. I want to write a simple shell script (called user) with an argument being a new created file (e.g. newfile). The script should find occurrence of the current users (e.g Richard.Jones), take that line and place it in the new created file (user) display a line number with bracket.

Do you mean find occurrences of  the current user in the argument file and place them with the line number in a newly created "user" file?

#!/bin/sh
if [ $# -lt 1 ] ; then
  echo usage $0 newfile
  exit 1
fi
grep -n $USER $1 >> user
ASKER CERTIFIED SOLUTION
Avatar of chingmd
chingmd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FirstMan
FirstMan

ASKER

thanks you solve the problem