I would like to join the result of ls -1
into one line and delimit it with whatever i want.
Are there any standard Linux commands I can use to achieve this?
The paste command can merge lines from multiple input files. By default, it merges lines in a way that entries in the first column belong to the first file, those in the second column are for the second file, and so on. The -s option can let it merge lines row-wise.
The sed way. 'N' joins 2 lines. And we replace the newline with a comma.
Method # 1 – Using echo & Printf The simplest way to append multiple lines to a file is to use the echo and printf command. Let us start with echo. Echo is a command used to output a string or multiple strings as arguments.
EDIT: Simply "ls -m" If you want your delimiter to be a comma
Ah, the power and simplicity !
ls -1 | tr '\n' ','
Change the comma "," to whatever you want. Note that this includes a "trailing comma" (for lists that end with a newline)
Similar to the very first option but omits the trailing delimiter
ls -1 | paste -sd "," -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With