Wednesday, April 27, 2022

[SOLVED] How to convert a multiple line input into single/multiple line output | BASH

Issue

What I really want

Input:

<int> 
45
</int>
<string>
Name
</string>

output:

<int> 45 </int>
<string> Name </string>

Here is what I've come up w/ so far(needs tweaking) for the desired output above:

printf "please enter some values \n"
readarray -t arr 

echo "" ${arr[@]} && cat >> input.txt

my output: <int> 45 </int> <string> Name </string>


Solution

Using printf

$ printf '%s %s %s\n' $(cat input.txt)
<int> 45 </int>
<string> Name </string>


Answered By - HatLess
Answer Checked By - Robin (WPSolving Admin)