The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can df output be forced to a single line for each file system? shew01 Shell Programming and Scripting 6 06-05-2008 08:25 AM
Multi-line output to single line LinuxRacr Shell Programming and Scripting 7 02-26-2008 06:05 AM
run command Unix on a single line Riddick61 UNIX for Dummies Questions & Answers 8 02-04-2008 10:19 AM
single line command roshanjain2 Shell Programming and Scripting 4 02-07-2007 01:33 AM
Need output in different lines not in one single line csaha Shell Programming and Scripting 1 02-08-2006 04:28 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 14
ls command output in single line

Hi,

Can anyone suggest me how can I display the output of ls command in single line with some delimiter say pipe (|)?

I know it can be done by writing a script by using the loops but I wanted to know are there any other single line commands?

Thanks for your help
Sheshadri
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-19-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
If you have GNU ls, try:

Code:
ls -m
The command writes the file listing separated by commas. Otherwise:

Code:
ls -1 | awk '{ ORS="|"; print; }'
Reply With Quote
  #3 (permalink)  
Old 08-19-2007
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,502
Quote:
Originally Posted by robotronic View Post
Code:
ls -1 | awk '{ ORS="|"; print; }'
The -1 option serves no purpose here.

Code:
printf "%s|" *
Reply With Quote
  #4 (permalink)  
Old 08-19-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Wow reborg

Very cool solution!
Reply With Quote
  #5 (permalink)  
Old 08-20-2007
Registered User
 

Join Date: Jan 2007
Posts: 14
Thank you guys.
Reply With Quote
  #6 (permalink)  
Old 04-28-2008
Registered User
 

Join Date: Apr 2008
Posts: 8
This is great
ls file* | awk '{ ORS="|"; print; }'

But what if you want to put something in between?
For example:
file1|<filler1>|file2|<filler2>|file3|<filler3>|file4....

Thanks.
Reply With Quote
  #7 (permalink)  
Old 04-28-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,032
reborg wrote about eras usage of "ls -1":

Quote:
Originally Posted by reborg View Post
The -1 option serves no purpose here.
This is a common misunderstanding about "ls". Because "ls" output has several columns when displayed on a screen one would assume that the same is the case when the output goes into a pipe. In fact "ls" determines if its output goes to a terminal or not and formats its output in columns or not. This can easily be demonstrated by issuing "ls > /some/file ; cat /some/file", which will show the same output as "ls -1" (to the screen), whereas "ls" (to the screen) will look different.

(source: the AIX manpage of ls tells about this rather counter-intuitive behavior of ls)

bakunin
Reply With Quote
Google UNIX.COM
Reply

Tags
linux, ubuntu

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0