Link to home
Start Free TrialLog in
Avatar of Mrdogkick
Mrdogkick

asked on

simple problem i think...

I have written the following script which should find all the occurences of a particular user in the xx file and print them to an other file (user). This all work and my output looks like this:

1  OLDPWD=/home/hussain.ahmed
2  USER=hussain.ahmed
3  MAIL=/var/spool/mail/hussain.ahmed
 Something very annoying but I want each line number to have a bracket after it. ie

1)........
2)..............
etc.

Any ideas??
#!/bin/bash
file=/home/hussain.ahmed/coursework/chapter7/xx
grep $USER $file | nl >/home/hussain.ahmed/coursework/chapter7/user

Open in new window

Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Try

#!/bin/bash
file=/home/hussain.ahmed/coursework/chapter7/xx
grep $USER $file | nl >/home/hussain.ahmed/coursework/chapter7/user | sed s/\ /\)\ /
Avatar of Mrdogkick
Mrdogkick

ASKER

isn't there a way I could say 'cut into the first space of each line and add a ")"'?
Well, I am not sure if there is simple command that can give you this.

Did you try yhe solution?

grep $USER $file | sed = | paste -s -d ')\n' - -




Sorry I put sed in the wrong place. Please try

#!/bin/bash
file=/home/hussain.ahmed/coursework/chapter7/xx
grep $USER $file | nl   | sed s/\ /\)\ /  > /home/hussain.ahmed/coursework/chapter7/user
I am actually trying to do this without the use of sed or AWK? any ideas?
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

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