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. |
Quote:
|
in addition to cut, sed and awk, tr will also work ;)
|
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 |
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. |
Quote:
Also, if you have replaced colons ( : ) with spaces, then I would use the space as field separator in awk |
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. |
Quote:
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 |
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.
|
All times are GMT -5. The time now is 04:40 PM. |