What's a quick way to do this, /g/?
Pic should be self-explanatory, but I essentially want to combine Text 1 and 2, with line 1 of Text 1 being followed by line 1 of Text 2, then line 2 of Text 1 followed line 2 of Text 2, etc.... in the resulting text
It'd also be nice if it could add an additional empty line like the Result Text in the picture for each pair of lines from Text 1 and 2, but not a necessity
>>58616608Prelude> zip ["aaaa", "bbbb"] ["cccc", "dddd"]
[("aaaa","cccc"),("bbbb","dddd")]
>>58616608
fizz buzz?
>>58616608
what are you doing one of those take home interviews?
>>58616608#!/bin/bash
IFS=$'\n'
ar1=($text1)
ar2=($text2)
printf '%s\n' "$ar1" "$ar2" "${ar1[1]}" "${ar2[1]}"
>>58616608
If you want that empty line#!/bin/bash
IFS=$'\n'
ar1=($text1)
ar2=($text2)
printf '%s\n' "$ar1" "$ar2" '' "${ar1[1]}" "${ar2[1]}"
>>58616892
>>58616845
>printf in bash
>>58616608
text 1 on tape #1
text 2 on tape #2
begin
read tape #1
put tape #3
read tape tape #2
put tape #3
if not tape end goto begin
>>58616926
Yes, so? How would you do that in echo, print every arguments in multiple lines? You'd have to make multiple calls to echo, or make a helper function.echolines() {
for a; do
echo "$a"
done
}
Using printf this way is way cleaner. Plus, it's got some neat features, like quoting and displaying dates. It's even more portable, the -e/-n situation in echo is a portability mess. Speaking of echo, you can't use "--" in it, so there's no way to prevent user input from disappearing when they specify either one of -e, -n, -en, or -ne. This does not happen in printf.
'\n\n'.join('\n'.join(pair) for pair in zip('AAAA\nBBBB'.split(), 'CCCC\nDDDD'.split()))
>>58617011
Could you mail me your punch card?
>>58616608
In Ruby:def zip_it(t1, t2)
t1.split.zip(t2.split).map{|i| i.join("\n") + "\n\n"}
end
puts zip_it("AAAA\nBBBB", "CCCC\nDDDD")
>>58617449
Sorry it's licensed under a non-free license.
However if you're willing to sign my End User License Agreement I could mail it to you
paste -d'\n' text1 text2
>>58616608
Use COBOL