Solved

simple problem i think...

Posted on 2007-12-07
7
240 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

746 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now