LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2005, 10:33 AM   #1
batalia
LQ Newbie
 
Registered: Nov 2005
Posts: 4

Rep: Reputation: 0
Need help with small program


Need to know how I would create this.

hanak:##chanak:10665:250::/home/home1/summer/chanak:/bin/bash
ling:##yling:9033:310::/home/home1/ugrad/yling:/bin/bash
sorgent:##tsorgent:10405:250::/home/home2/grads/sorgent:/bin/bash
cappucc:##gcappucc:9140:310::/home/home1/ugrad/cappucc:/bin/bash
abbott:##tabbott:11223:280::/home/home1/spring/tabbott:/bin/bash
smith1:##msmith1:10431:250::/home/home2/grads/smith1:/bin/bash
henson:##mhenson:9498:310::/home/home1/ugrad/henson:/bin/bash
naeemi:##hnaeemi:10090:310::/home/home1/ugrad/naeemi:/bin/bash
rucker:##drucker:9041:310::/home/home1/ugrad/rucker:/bin/bash
rao:##rrao:8825:320::/home/home3/phd/rao:/bin/bash

1) remove all the ":"
Hint: use the command "cut"
2) substitute grads with others and ugrad with another

3) print username, userID and Home directory
Hint: use awk

4) Format the output in "3)" with headers:

USER Name User ID Home Directory
xxxxx xxxxx xxxxx


would appriciate the help.
 
Old 11-05-2005, 11:00 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
Hint: use the command "cut"
Yep! Also with sed and awk you should have no problem finishing your homework before Monday.
 
Old 11-05-2005, 11:46 AM   #3
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 48
in addition to cut, sed and awk, tr will also work

Last edited by alienDog; 11-05-2005 at 11:48 AM.
 
Old 11-05-2005, 02:01 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Keep up the good work, guys, hints to how to solve
his homework are fine, a plain doing his job isn't.

To batalia:
Please read the rules you agreed to again - homework
questions ARE NOT ALLOWED.


Cheers,
Tink
 
Old 11-06-2005, 07:04 PM   #5
batalia
LQ Newbie
 
Registered: Nov 2005
Posts: 4

Original Poster
Rep: Reputation: 0
I have 90% of this done. The commands I've used are

sed 's/:/ /g' project1

That removes all the semicolons

sed 's/grads/others/g' project1

sed 's/ugrad/another/g' project1

What I'm having problems with is adding the headings.

I've used the awk '{print "USER Name User ID Home Directory" }' project1

but that command places the USER Name User ID Home Directory at the ends of each line. Can someone help me with fixing this line of printing so I can add the headers to the file.
 
Old 11-06-2005, 10:59 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
I've used the awk '{print "USER Name User ID Home Directory" }' project1
You're coming right along with that. I would use BEGIN to print the header and tabs ( \t ) between them.
Also, if you have replaced colons ( : ) with spaces, then I would use the space as field separator in awk
 
Old 11-07-2005, 07:39 AM   #7
batalia
LQ Newbie
 
Registered: Nov 2005
Posts: 4

Original Poster
Rep: Reputation: 0
i've used this type of command

awk 'begin{print "USER Name User ID Home Directory" }' but what happens is ir prints username user id homedirectoy at the end of each line on all of the lines and not just ontop one time. Don't know what I'm doing wrong on this one.
 
Old 11-07-2005, 08:18 AM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
awk 'begin{print "USER Name User ID Home Directory" }'
The word BEGIN is in caps. The header is only part of the picture, you still need to print the colums with data in them.
Don't forget to separate the columns with tabs.
For example: 'BEGIN {User Name\tUser ID\t\tHome Directory}

Don't forget the Input Field Separator. For example: awk -F:
Don't forget the Output Field Separator. For example: {OFS="\t\t"}
Don't forget to choose the columns which you want to print.
For example: {print$1,$3,$6}' project1

Last edited by homey; 11-07-2005 at 08:23 AM.
 
Old 11-07-2005, 02:41 PM   #9
batalia
LQ Newbie
 
Registered: Nov 2005
Posts: 4

Original Poster
Rep: Reputation: 0
I think thats what I needed. Thanx a ton, I'm in college and the teacher teaches the class like everyone knows linux 100%. I was missing this {print$1,$3,$6}' project1 and the rest. Was giving me all kinds of strange results and linux is not like c++ or Visual basic. It doesnt tell you whats wrong. Thanx again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile a small program Dauer Ubuntu 2 11-05-2005 04:17 AM
Help me install program on Damn Small Linux atyndall DamnSmallLinux 2 06-23-2005 09:22 AM
How can you reverse engineer a small C program OrganicX Programming 1 01-30-2004 08:30 PM
A small program to stop iptables satimis Linux - Newbie 6 09-15-2003 12:04 AM
Asking anyone who will make a small program for free. weblion Programming 7 12-02-2001 09:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration