• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

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???
0
FirstMan
Asked:
FirstMan
1 Solution
 
ozoCommented:
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
0
 
chingmdCommented:
I'm not understanding the question either.   I do get that you are trying to get the username of the currently logged in user.   without set or awk.

This is what I used.

env | grep USER | cut -f2 -d"="

Assuming that the output is like this
USER=<username>

So what is it that you wanted to do with the user name?  


0
 
FirstManAuthor Commented:
thanks you solve the problem
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now