?
Solved

simple problem i think...

Posted on 2007-12-07
7
Medium Priority
?
248 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:
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.
Suggested Courses

765 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