The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > 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 11:25 AM
Multi-line output to single line LinuxRacr Shell Programming and Scripting 7 02-26-2008 10:05 AM
run command Unix on a single line Riddick61 UNIX for Dummies Questions & Answers 8 02-04-2008 02:19 PM
single line command roshanjain2 Shell Programming and Scripting 4 02-07-2007 05:33 AM
Need output in different lines not in one single line csaha Shell Programming and Scripting 1 02-08-2006 08:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2007
arsheshadri arsheshadri is offline
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
  #2 (permalink)  
Old 08-19-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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; }'
  #3 (permalink)  
Old 08-19-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Quote:
Originally Posted by robotronic View Post
Code:
ls -1 | awk '{ ORS="|"; print; }'
The -1 option serves no purpose here.

Code:
printf "%s|" *
  #4 (permalink)  
Old 08-19-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

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

Very cool solution!
  #5 (permalink)  
Old 08-20-2007
arsheshadri arsheshadri is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 14
Thank you guys.
  #6 (permalink)  
Old 04-28-2008
xinoo xinoo is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 12
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.
  #7 (permalink)  
Old 04-28-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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
Sponsored Links
Closed Thread

Bookmarks

Tags
linux, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0