jahan
jahan

Reputation: 521

Redirecting output of cat to sort

I have the following problem: Names of cities should be accepted from the keyboard. This list of cities should be combined with the list of cities present in the file cityfile. This combined list should be sorted and the sorted output should be stored in a file newfile. I have to solve it using pipelining. I wrote following pipelines:

cat >>  cityfile | sort > newfile

sort | cat >> cityfile >  newfile

How can I pass data of cityfile to sort command ?

Upvotes: 0

Views: 1723

Answers (2)

chepner
chepner

Reputation: 531888

Based on your comment, you need to separate this into two steps: append the new cities to the list first, then sort.

cat >> filename
sort filename > newfile

Upvotes: 1

ypnos
ypnos

Reputation: 52367

The cat command concatenates input. Input can be files or stdin. A common key for stdin is "-". This also holds for the cat command. So you would do:

cat - cityfile | sort > newfile

You can find this information with man cat.

Upvotes: 2

Related Questions