LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   ls command!!! (https://www.linuxquestions.org/questions/linux-enterprise-47/ls-command-687883/)

JATA01 12-02-2008 09:25 PM

ls command!!!
 
Hi Friends,

I have a question about ls command.

#ls -l
x
y
z

#ls -m
x, y, z

But my question is to print the output like:
x, y and z.

What approach should I be using to get the exact result?

Thanks-

pixellany 12-02-2008 11:09 PM

Do you have reason to believe that ls will do that? The man page does not seem to include that option.

I'm guessing that you will have to pipe the output into another command (eg SED).

JATA01 12-03-2008 04:12 AM

Now it can be done like this:--

[test@gfmdatabase test]$ y=`ls -m try`;echo "${y%,*} and ${y##*,}"
hello and script1


Thank you!!

pixellany 12-03-2008 08:05 AM

And here is a SED solution:

ls -m|sed 's/ \([^,]*\)$/ and \1/'


All times are GMT -5. The time now is 06:56 AM.