aspose file tools*
The moose likes Linux / UNIX and the fly likes how the the same operation with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how the the same operation with "pipe"..." Watch "how the the same operation with "pipe"..." New topic
Author

how the the same operation with "pipe"...

johny walker
Greenhorn

Joined: Nov 23, 2007
Posts: 6
4.Sorting:
a.Create a file called days that contain the days of the week, one per line.
b.Use a pipe to display a sorted list of the days to the screen.
c.Repeat b) but direct the output to a file called days_sort.

i found a way to do all of them
4a)printf "Sunday\nMunday\nTuesday\nWednesday\nThursday\nFriday" >days
4b) cat days
4c) cat days >days_sort
its a very simple commands to execute
i have no idea how the make them in another way
using pipe??
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

This sounds a lot like a homework exercise, so I am going to give hints here.

First up, you need to understand pipelines. I would suggest looking at the man page for bash (man bash) and searching for the word pipe (while looking at the man page, you can use the '/' character to start a search string, so you could type '/pipe' to jump to the information on pipelines (of course you could read the entire man page, and find a whole lot of other valuable information ).

Once you understand pipelines, you might want to look at the sort command. Once again, man is your friend: man sort.

You have created your file in calendar sort order. Given that, I would expect the result of the sorting in 4b to use some other sort order - alphabetical sort would be my choice.

In my opinion, using a pipe to do this is overkill given the size of your input and the fact that sort can do everything by itself. However this is all learning for bigger tasks, so I can see why they are getting you to crack the walnut with a sledgehammer. For that reason, since you have been explicitly asked to use the pipe command, I would continue to use the cat statement and pipe it through other commands.

A little more overkill - you might want to look at the more and less commands (in many modern versions of *nix environments, more and less are the same command). Once again use man to find out what they do. In step 4b) you could pipe the sorted output to either more or less. As mentioned earlier, this is overkill (especially since you only have 7 lines), but if you had more than a screen's worth of data then this would be very beneficial.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
johny walker
Greenhorn

Joined: Nov 23, 2007
Posts: 6
about 4c

does command > file_name

is a "pipe" form too??
johny walker
Greenhorn

Joined: Nov 23, 2007
Posts: 6
i tried to use pipe
to create a file

but the only coomand i know that creates a file
is ">"

???
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
The way I undersand it the symbol pipe "|" is used to send the standard output of a command to the left of the pipe as standard input to a command to the right of the pipe.

You cannot use "|" to create files like ">". Which is used to redirect standard output to a file.

The "|" is used to redirect standard output of a command to another command not another file.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I understand question b as to use the command 'sort':


which of course will sort alphabetically.


http://home.arcor.de/hirnstrom/bewerbung
 
wood burning stoves
 
subject: how the the same operation with "pipe"...