• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
johny walker
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
about 4c

does command > file_name

is a "pipe" form too??
 
johny walker
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried to use pipe
to create a file

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

???
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand question b as to use the command 'sort':


which of course will sort alphabetically.
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!