Help!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help!!!
# 1  
Old 04-04-2008
Bug Help!!!

Hi ya

I need some help please I am trying to read an input file 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.

so far i created a file xx
with env sent to it 5 times

then i created this script but I only manged to get 1) next to each line that greped from the xx file which contained env 5 times: -

echo "Enter the file name to search username: "
read fileName
egrep -w "PWD" $fileName | head -1 | nl -ba -w1 -s\) >> test
egrep -w "USER" $fileName | head -1 | nl -ba -w1 -s\) >> test
egrep -w "MAIL" $fileName | head -1 | nl -ba -w1 -s\) >> test
egrep -w "LOGNAME" $fileName | head -1 | nl -ba -w1 -s\) >> test
egrep -w "HOME" $fileName | head -1 | nl -ba -w1 -s\) >> test

thanks in advance I have been racking my brains please help!!!!!
# 2  
Old 04-05-2008

When I ran that I got what I would expect:
Code:
$ cat test
1)PWD=/home/chris/tmp
1)USER=chris
1)MAIL=/var/spool/mail/chris
1)LOGNAME=chris
1)HOME=/home/chris

Did you expect something different?

Perhaps you wanted:

Code:
{
  egrep -w "PWD" $fileName | head -1
  egrep -w "USER" $fileName | head -1
  egrep -w "MAIL" $fileName | head -1
  egrep -w "LOGNAME" $fileName | head -1 
  egrep -w "HOME" $fileName | head -1
} | nl -ba -w1 -s\) > test

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question