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?
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?
You can use chomp to merge multiple line in single line:
perl -e 'while (<>) { if (/\$/ ) { chomp; } print ;}' bad0 >test
put line break condition in if statement.It can be special character or any delimiter.
Don't reinvent the wheel.
It does exactly that.
If you version of xargs supports the -d flag then this should work
-d is the delimiter flag
If you do not have -d, then you can try the following
The first xargs allows you to specify your delimiter which is a comma in this example.
I think this one is awesome
ORS is the "output record separator" so now your lines will be joined with a comma.
The combination of setting
IFS
and use of"$*"
can do what you want. I'm using a subshell so I don't interfere with this shell's $IFSTo capture the output,
ls
produces one column output when connected to a pipe, so the-1
is redundant.Here's another perl answer using the builtin
join
function which doesn't leave a trailing delimiter:The obscure
-0777
makes perl read all the input before running the program.sed alternative that doesn't leave a trailing delimiter