if i do this 5 times
env >> xx
env >> xx
env >> xx
env >> xx
env >> xx
il will a file called XX with the env redirected into it 5 times
i need to create a script that takes 1 argument being a file, in this instancei ll use the newly created file above xx read the inputted file, in this case xx and look for occurrences of the current user who is executing the script. On finding an occurrence of the username take that line and append it to a file and display a line number and a bracket against the saved line.
The newly created file should look similar to this
1) PWD=/home/lee.ballancore
2) USER=lee.ballancore
3) MAIL=/var/spool/mail/lee.ballancore
4) LOGNAME=lee.ballancore
5) HOME=/home/lee.ballancore
6) PWD=/home/lee.ballancore
7) USER=lee.ballancore
8) MAIL=/var/spool/mail/lee.ballancore
9) LOGNAME=lee.ballancore
10) HOME=/home/lee.ballancore
Initialize counter (value 0)
Display the current environment variables
and For each line do
If the line contains le username then
increment the counter
display counter and line.
You can do that with the commands :
case echo env expr for if read
Ciro,
As Vino said, if this is a homework, besides breaking this site rules,
you are cheating yourself.
The only way you will learn is to practice.
If this is not a homework:
You will not learn anything if you don't try to resolve the problems by yourself before posting.
Read the grep man pages
As you don't want to use awk nor sed, you can read the output of the cat command with the read command in a while loop.
The read command permits to read the first word in a variable and the rest of the line in another one.
RTFM.
this is the output i was looking for!!!!
just need to add a bracket on ech number and i do not know how to do it
[ciro.ruggiero@unix ~]$ grep $USER xx | cat -n
I am closing this thread. Enough information was given in several posts by three memmbers to answer the questions. Other posts have given information about where to look for a solution if you don't like the ones provided. It benefits nobody to continue with this.