1

I have a file fruits:

apple grapes banana orange 

By using

cat < fruits | tr "\n" "," 

It will give output as

apple,grapes,banana,orange, 

Here I want to print the file name also along with the output like

fruits|apple,grapes,banana,orange 

How can I do it?

If it is a variable like

$HEALTHYFRUITS

where we read all the fruits one by one and the file name is fruits

and

echo $HEALTHYFRUITS | tr "\n" ","

here I want to print

fruits|apple,grapes,banana,orange

1 Answer 1

3
echo -n "$filename|"; tr "\n" "," <"$filename" 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.