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

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

0
Mrdogkick
Asked:
Mrdogkick
  • 4
  • 2
1 Solution
 
omarfaridCommented:
Try

#!/bin/bash
file=/home/hussain.ahmed/coursework/chapter7/xx
grep $USER $file | nl >/home/hussain.ahmed/coursework/chapter7/user | sed s/\ /\)\ /
0
 
MrdogkickAuthor Commented:
isn't there a way I could say 'cut into the first space of each line and add a ")"'?
0
 
omarfaridCommented:
Well, I am not sure if there is simple command that can give you this.

Did you try yhe solution?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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


0
 
omarfaridCommented:


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
0
 
MrdogkickAuthor Commented:
I am actually trying to do this without the use of sed or AWK? any ideas?
0
 
omarfaridCommented:
Just use the -s option with nl. Please see:


#!/bin/bash
file=/home/hussain.ahmed/coursework/chapter7/xx
grep $USER $file | nl -s") " > /home/hussain.ahmed/coursework/chapter7/user
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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