Make/Convert list of text into block of text

Viewed 41

I would like to take a text-file containing a list of installed packages, each on a separate line, and join them into a single line. My current shell-script looks like this:

#!/bin/sh
sed -i '1 i\sudo pacman -Syu' pkglist.txt
sed -i 's/$/ /' pkglist.txt

And my pkglist.txt file looks a like this:

sudo pacman -Syu  
accountsservice 
adobe-source-han-sans-cn-fonts 
adobe-source-han-sans-jp-fonts 
adobe-source-han-sans-kr-fonts 
adobe-source-sans-fonts 
aic94xx-firmware 
...

My desired final look of pkglist.txt is something like this:

sudo pacman -Syu accountsservice adobe-source-han-sans-cn-fonts adobe-source-han-sans-jp-fonts adobe-source-han-sans-kr-fonts adobe-source-sans-fonts aic94xx-firmware ...
2 Answers

I suggest with bash:

sudo pacman -Syu $(paste -s pkglist.txt)

I assume sudo pacman -Syu is not part of pkglist.txt and no file name contains spaces or tabs.

xargs sudo pacman -Syu < pkglist.txt

This should do as you wish. No need to modify pkglist.txt to add the sudo packman at the start.

Related