Solved

simple problem i think...

Posted on 2007-12-07
7
243 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

785 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