Question: As mentioned in the title, I'm unable to simultaneously record my headset microphone *and* my desktop audio when using SimpleScreenRecorder in KDE Neon 5.24.

In the "Audio Input" section of the recording settings, I selected "PulseAudio" as **Backend**, whereas for **Source** I've tried both "Built-in Audio Analog Stereo" as well as "Monitor of Built-in Audio Analog Stereo" (see below):

[![enter image description here](https://i.stack.imgur.com/Iagkh.png)](https://i.stack.imgur.com/Iagkh.png)

When selecting "Built-in Audio Analog Stereo", the microphone gets recorded but the desktop audio does not, while the situation is exactly the opposite when I select "Monitor of Built-in Audio Analog Stereo" (can record desktop audio but not headset microphone).

Does anybody have an idea of how to solve this issue?

Answer: 
Making use of paragraph mode (-00) in Perl:

```bsh
perl -pals -F'\n' -00e 's/.*/@F/s' -- -\"=, file

```

---

Perl in line by line mode:

```bsh
perl -pe '
  chomp($_.=<>.<>),tr/\n/,/ if/./;
  eof && s/.\K$/\n/;
' file

```

---

POSIXly sed :

```bsh
sed '
  /./{H;$!d;}
  x;y/\n/,/;s/.//
' file

```

---

We can do this using `GNU csplit + xargs paste` pipeline

```bsh
csplit --suppress-matched -sz file '/^$/' '{*}'
printf '%s\n' xx* | xargs -r paste -sd,

```

---

Using `groupby` method from the `itertools` module in Python along with list comprehension:

```bsh

python3 -c 'import sys, itertools as it

ofs,(rs,ors) = ",","\n" * 2
g = lambda x: not len(x)
h = lambda x: x.rstrip(rs)

with open(sys.argv[1]) as f:
  print(*[ofs.join(igrp) for k,igrp in it.groupby(map(h,f),g) if not k],sep=ors)
' file

```

---

Output:-

```
St1,number1,1234
St2,number2,456

```

---
Using **Raku** (formerly known as Perl\_6)

Probably the most robust solution simulates Perl's `-00` paragraph mode:

```perl
raku -e '.put for lines.join("\n").split(/\n**2..*/).map(*.trans: "\n" => ",");'  

```

Sample Input

```
St1
number1
1234

St2
number2
456

```

Sample Output

```
St1,number1,1234
St2,number2,456

```

The answer above uses Raku's `lines` routine, which reads input lines lazily and strips newlines by default. Basically with the code above, `lines` are read in, `join`-ed back again with newlines, and split where `\n**2..*` two-or-more consecutive newlines are found. Then each element is `map`-ped into and remaining single `\n` newlines are translated to commas. Finally the resultant elements are output using Raku's `.put for...` idiom *('put' stands for 'print-using-[newline]-terminator')*.

Again, above is the most robust solution. However you can get a similar result with simpler code, assuming you you don't mind receiving output with terminal "`,`" commas. The code exploits the difference between `print` (no terminal newline) and `put` (adds terminal newline):

```perl
raku -ne 'if .chars { print $_~"," } else { put $_ };'    

```

The code above preserves line-spacing where sections are separated by multiple consecutive blank lines (unlike the first answer, which removes all blank lines).

<https://unix.stackexchange.com/a/686651/227738>  

<https://docs.raku.org/type/Cool#routine_lines>  

<https://raku.org>