Search code examples
linuxbashshellawkls

unix concatenate list of files into on line


In a directory, there is several files such as:

file1 
file2 
file3

Is there a simple way to concatenate those files to get one line (connected by "OR") in bash as follows:

file1 OR file2 OR file3

Or do I need to write a script for it?


Solution

  • You can simply do that with

    printf '%s OR ' $(ls -1 *) | sed 's/OR $/''/'; echo -e '\n'
    

    Where ls -1 * is the directory.