Can someone please help me? (Another example of how not to post homework.)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can someone please help me? (Another example of how not to post homework.)
# 1  
Old 01-29-2010
Can someone please help me? (Another example of how not to post homework.)

Hi,
when I run ls -l I get the following command (I already know ls) :
Code:
rwxrwxrwx 2 andrew andrew 4096 2010-01-25 22:00 test.txt
rwxrwxrwx 2 andrew andrew 4096 2010-01-25 21:01 test1.txt
rwxrwxrwx 3 andrew andrew 4096 2010-01-25 20:45 test2.txt
rwxrwxrwx 1 andrew andrew 4096 2010-01-25 01:12 test3.txt

I want to write a bash program that uses : cut, grep, sed and pipes
and makes the output asfollow (I know ls give me the name only,but i have to use ls -l):
Code:
-test.txt
-test1.txt
-test2.txt
-test3.txt

(there has to be a dash)


what should I use(I just know I should use the pipe):
ls -l |

Last edited by Yogesh Sawant; 01-29-2010 at 03:45 AM.. Reason: added code tags
# 2  
Old 01-29-2010
am not sure, Is this what are you looking for ?
Code:
ls -l|awk '{ print "-"$8 }'


Last edited by Yogesh Sawant; 01-29-2010 at 03:44 AM.. Reason: added code tags
# 3  
Old 01-29-2010
Hello,
Searching forum database you could find this solution very easily:

Code:
ls -l | awk '/^-/ {print "-"$9}'

# 4  
Old 01-29-2010
Hmmm, sounds like home work to me. Smilie
# 5  
Old 01-29-2010
Code:
ls -l | awk '/^-/ {print "-"$NF}'

Code:
ls -l | sed -n 's/^-.* /-/p'

# 6  
Old 01-29-2010
Quote:
Originally Posted by andrew1400
I want to write a bash program ........ what should I use(I just know I should use the pipe):
Look like a homework to me (see Forum Rules) if not:
Code:
for i in *.txt;do echo -${i};done

You don't need cut, grep, sed and pipes.
# 7  
Old 01-29-2010
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Apparently my post is Homework/Classwork?

I previously posted a question in the Shell Scripting forum a few minutes ago. I recieved a message telling me I had breached a rule, apparently because my post was a homework infraction. Well, im currently trying to figure out how to use Raspberry Pi's (as im a starter) I asked one of my... (1 Reply)
Discussion started by: Waggie14
1 Replies

2. Post Here to Contact Site Administrators and Moderators

Do I post to Homework forum if learning on own

Quick question, I'm learning shell scripting on my own from resources like the 'Teach Yourself' books, web sites, etc. If I have any questions about these materials, do I still need to post them to the homework section? The template asks specific things like school associated with or... (7 Replies)
Discussion started by: Chasman78
7 Replies

3. Post Here to Contact Site Administrators and Moderators

Help with deleting post, apologies about the earlier post.

Apologies about the earlier post, i didnt realise, could i delete that post? I apologise again, SynGc (1 Reply)
Discussion started by: SynGc
1 Replies

4. Homework & Coursework Questions

Can someone please help me? (An example of how not to post homework.)

Hi, when I run ls -l I get the following command (I already know ls) : Code: rwxrwxrwx 2 andrew andrew 4096 2010-01-25 22:00 test.txt rwxrwxrwx 2 andrew andrew 4096 2010-01-25 21:01 test1.txt rwxrwxrwx 3 andrew andrew 4096 2010-01-25 20:45 test2.txt rwxrwxrwx 1 andrew andrew 4096... (1 Reply)
Discussion started by: andrew1400
1 Replies
Login or Register to Ask a Question