Solved

simple problem i think...

Posted on 2007-12-07
7
247 Views
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

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
Comment
Question by:Mrdogkick
[X]
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
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20426775
Try

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

Author Comment

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

Expert Comment

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

Did you try yhe solution?

0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 84

Expert Comment

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


0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20426975


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
 

Author Comment

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

Accepted Solution

by:
omarfarid earned 125 total points
ID: 20427081
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

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!

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

707 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