simple problem i think...

Posted on 2007-12-07
Last Modified: 2010-04-21
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


Any ideas??
grep $USER $file | nl >/home/hussain.ahmed/coursework/chapter7/user

Open in new window

Question by:Mrdogkick
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 40

Expert Comment

ID: 20426775

grep $USER $file | nl >/home/hussain.ahmed/coursework/chapter7/user | sed s/\ /\)\ /

Author Comment

ID: 20426828
isn't there a way I could say 'cut into the first space of each line and add a ")"'?
LVL 40

Expert Comment

ID: 20426864
Well, I am not sure if there is simple command that can give you this.

Did you try yhe solution?

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 84

Expert Comment

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

LVL 40

Expert Comment

ID: 20426975

Sorry I put sed in the wrong place. Please try

grep $USER $file | nl   | sed s/\ /\)\ /  > /home/hussain.ahmed/coursework/chapter7/user

Author Comment

ID: 20426997
I am actually trying to do this without the use of sed or AWK? any ideas?
LVL 40

Accepted Solution

omarfarid earned 125 total points
ID: 20427081
Just use the -s option with nl. Please see:

grep $USER $file | nl -s") " > /home/hussain.ahmed/coursework/chapter7/user

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Grep to Find a file 8 118
Sparc Solaris hangs without crash dump & no events from messages 3 101
Unix Question 19 56
unix solaris snoop command 6 138
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

732 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