Lum – How to concatenate a single column of output into a list

columnsgrepls

I'm using:

ls /proc | grep -v "^[0-9].*"

to get a list of all the files and directories in /proc that don't begin with numbers. The output is a single column list, i.e.:

acpi
asound
buddyinfo
bus

How can I make this a multi-column or item list, i.e.:

acpi asound buddyinfo bus

or

acpi,asound,buddyinfo,bus

I tried:

$ ls /proc | grep -v "^[0-9].*" | column -c5

but still got 1 column.

Best Answer

Use xargs:

$ command ls /proc | grep -v "^[0-9].*" | xargs

The command part is necessary because if your ls is aliased to ls --color for example, it adds non-printing escape sequences to its output that grep somehow searches through and produces undesirable results.


Other options

If you don't mind your PWD changing:

$ cd /proc && echo [^0-9]*

If you don't want to change your PWD:

$ pushd . &>/dev/null && cd /proc && echo [^0-9]* && popd &>/dev/null

Or:

$ echo /proc/[^0-9]* | sed 's!/proc/!!g'
Related Question