PDA

View Full Version : bash syntax question



mynamewastaken
March 6th, 2007, 06:53 AM
cut -d: -f1 < /etc/passwd | sort | xargs echo

Is there some advantage to doing it this way instead of cat/more/less /etc/passwd > cut ?

Only thing I can think of is it cuts out the cat/more/less...

mynamewastaken
March 6th, 2007, 07:05 AM
cut -d: -f1 < /etc/passwd | sort | xargs echo

Is there some advantage to doing it this way instead of cat/more/less /etc/passwd > cut ?

Only thing I can think of is it cuts out the cat/more/less...

ghostdog74
March 6th, 2007, 08:59 AM
cut -d: -f1 < /etc/passwd | sort | xargs echo

Is there some advantage to doing it this way instead of cat/more/less /etc/passwd > cut ?

Only thing I can think of is it cuts out the cat/more/less...

this command gets only the username in /etc/passwd. another way is


awk -F":" '{print $1}' /etc/passwd

without sorting. The difference is you do not need to use too many shell tools piped together.

Mr. C.
March 6th, 2007, 10:29 AM
The cut command accepts a filename as an argument. You do not need to redirect from STDIN (eg. cut /etc/passwd).

The line:

cat/more/less /etc/passwd > cut

will create a file name "cut".

See Week 4 Coursework here: http://cis68a.mikecappella.com/ and Week 11 (Loose Ends) here: http://cis68b1.mikecappella.com/calendar.php

This will give an explanation about your question regarding "cat"...

MrC

kidders
March 6th, 2007, 11:59 AM
(oops... sorry)

mynamewastaken
March 7th, 2007, 09:34 AM
The cut command accepts a filename as an argument. You do not need to redirect from STDIN (eg. cut /etc/passwd).

The line:

cat/more/less /etc/passwd > cut

will create a file name "cut".

See Week 4 Coursework here: http://cis68a.mikecappella.com/ and Week 11 (Loose Ends) here: http://cis68b1.mikecappella.com/calendar.php

This will give an explanation about your question regarding "cat"...

MrC


Aye, just made a stupid typo a > where it should have been a pipe. I suppose my main question still stands in that is the only advantage to doing it that way saving out on the cat/less/more command?

Mr. C.
March 7th, 2007, 09:46 AM
I gave you the answer!

... Week 11 (Loose Ends) here: http://cis68b1.mikecappella.com/calendar.php

This will give an explanation about your question regarding "cat"...