-2

The input to tsort can be provided as in this example:

$ tsort <<EOF
a b c
b c d e
EOF

If I have two files as inputs instead,

a
b
c

and

b
c
d
e

how can I provide the two files in bash as inputs to tsort ? Thanks.

closed as unclear what you're asking by muru, Thomas, mosvy, Isaac, RalfFriedl Nov 18 '18 at 0:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

You need to put all entries of each file into a single line.

You can do so with an unquoted $(...) which will split on whitespace (and that includes newline) and then you can use echo on it to print the arguments into a single line.

This should work:

{ echo $(cat file1)
  echo $(cat file2)
} | tsort

This should produce the same output as your example does.


UPDATE: The input of tsort is broken on any whitespace, so preserving each file's contents in a single line isn't really important.

In that case, this should be enough:

cat file1 file2 | tsort

Though in your example, you don't really have a number of pairs, there is an odd number of items in your file1. As you noticed already, that is a problem for tsort.

Not the answer you're looking for? Browse other questions tagged or ask your own question.