?
Solved

SOME HELP

Posted on 2007-10-05
6
Medium Priority
?
209 Views
Last Modified: 2010-04-21
I have a question which i require assistance with

i have run the environment settings a number of times and assigned it to a file called 'xx', i did this by
typing ''env >> xx". nowi want to create a script named 'username' holds 1 argument being a file called 'xx'. I have read the input and saw occurence of my usename a few time. What i want to achiveve is to extract the lines of occurence and place it to a new file, display a line number and a bracket against the saved line.

I have already identified the environment,

PATH
USER
MAIL
PWD
HOME
LOGNAME

but i need help with the script called 'usename'. can u help me?!
0
Comment
Question by:FirstMan
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:ghostdog74
ID: 20026221
I hope i  understand you correctly. you don't have to create an intermediate step. you can do the env in your username script
eg
env | grep "what you want to find"
0
 

Author Comment

by:FirstMan
ID: 20027293
ok thank for your comment. i used your solution and it works perfectly but i wanted to create a script within the file to find an occurrence of the username ,(e.g. HOME=/home/adam.adebisi) take this line and copy it to a file and display a line number with a bracket against the saved line.

i wanted the output to resemble this

1)USER=adam.adebisi
2)MAIL=/var/spool/mail/adam.adebisi
3)PATH=/u01/app/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/
local/bin:/bin:/usr/bin:/home/adam.adebisi/bin
4)PWD=/home/adam.adebisi
5)HOME=/home/adam.adebisi
6)LOGNAME=adam.adebisi
7)USER=adam.adebisi
8)MAIL=/var/spool/mail/adam.adebisi
9)PATH=/u01/app/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/
local/bin:/bin:/usr/bin:/home/adam.adebisi/bin
10)PWD=/home/adam.adebisi
11)HOME=/home/adam.adebisi
12)LOGNAME=adam.adebisi

i typed in the given solution

env | grep $USER

and dispay this output

USER=adam.adebisi
MAIL=/var/spool/mail/adam.adebisi
PATH=/u01/app/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/adam.adebisi/bin
PWD=/home/adam.adebisi
HOME=/home/adam.adebisi
LOGNAME=adam.adebisi

can u help?


0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 20028066
try this:
env | awk -v user="$USER" '$0~user{ print c++")",$0}'
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:FirstMan
ID: 20028237
thanks for your solution and also the upgrade. But what i wanted is help writing a shell script which will take an argument (a file called xx) ,output the occurences of my username and display it with a line number and a bracket against a saved line.
0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 20029025
taking an argument in shell script:

#!/bin/sh
myfile = $1
....
...
awk -v user="$USER" '$0~user{ print c++")",$0}' $myfile
....
0
 
LVL 48

Accepted Solution

by:
Tintin earned 2000 total points
ID: 20031038
#!/bin/bash
file=/path/to/xx
grep $USER $file | nl >/path/to/saved-file
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question