LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 11-23-2009, 03:32 PM   #1
valen_tino
Member
 
Registered: Jan 2008
Posts: 105

Rep: Reputation: 28
Modifying the output of the ls command


Greetings to all,

I have an unusual request and here it goes.

On a RHEL 4.x system the output of a ls -l command is

Code:
-rw-r--r--  1 apps dba  428542 Dec  5  2005 file1
-rw-r--r--  1 apps dba  427561 Nov  8  2005 file2
-rw-r--r--  1 apps dba 1117081 Aug  9  2005 file3
-rw-r--r--  1 apps dba 3095798 Aug  9  2005 file4
-rw-r--r--  1 apps dba  107412 Aug  9  2005 file5
On a RHEL 5.x system the output of a ls -l command is

Quote:
-rw-rw-r-- 1 apps dba 6606 Sep 9 07:27 file1
-rw-rw-r-- 1 apps dba 18625 Sep 9 07:27 file2
-rw-rw-r-- 1 apps dba 514568 Sep 9 07:27 file3
-rw-rw-r-- 1 apps dba 2594142 Sep 9 07:27 file4
-rw-rw-r-- 1 apps dba 431433 Sep 9 07:27 file5
The problem that I have is that there are 2 blank spaces after -rw-r--r-- in RHEL 4.x and only 1 space in RHEL 5.x. Our mainframe job does not like this and spits errors while reading the file listing.

The question that I have is can the output of the ls command in RHEL 5.x be altered to include that extra space just like RHEL 4.x? We would prefer to go this route rather than change the mainframe job at this time.

I've been scratching my head but unable to get any leads. Any pointers would be greatly appreciated.
 
Old 11-23-2009, 03:49 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 39,800

Rep: Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111Reputation: 1111
well that is *NOT* the normal output for ls, must be something in your environment doing that somehow. does this happen as all users?
 
Old 11-23-2009, 03:52 PM   #3
rweaver
Senior Member
 
Registered: Dec 2008
Location: Independance, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 160Reputation: 160
You could reformat the results with sed or awk.

Although there may be an additional underlying issue with the term you're using in rh5 since that isn't normal output for a rh5 system (justification is off, etc. Although there is only one space in rh5 even when the output is normal.)

Off the top of my head...

Code:
ls -l | awk '{print $1, "", $2, $3, $4, $5, $6, $7, $8, $9}'
Although you'd be better off with the printf to make the justifications correct and such.
 
Old 11-23-2009, 03:55 PM   #4
valen_tino
Member
 
Registered: Jan 2008
Posts: 105

Original Poster
Rep: Reputation: 28
Thanks for the quick response.

What is not normal - having 2 spaces in RHEL 4.x or the 1 space in RHEL 5.x? What should the normal behavior be?

This behavior appears to be consistent across the few RHEL 4 and RHEL 5 servers that I checked.
 
Old 11-23-2009, 04:02 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: back to Arch
Posts: 16,641

Rep: Reputation: 423Reputation: 423Reputation: 423Reputation: 423Reputation: 423
It's more complicated than that. Here is a portion of my ls -l in $HOME:

Code:
drwx------  3 mherring users 4096 2009-11-23 08:52 Desktop
drwxr-xr-x  2 mherring users 4096 2009-11-23 12:37 Downloads
-rw-r--r--  1 mherring users  469 2009-10-29 17:51 cap      
drwxr-xr-x 13 mherring users 4096 2009-11-23 12:36 docs
Note 2 spaces except where the first number has 2 digits.

To simply get ls -l to always have 2 spaces, try this:

Code:
ls -l|sed 's/ \+/  /1'
(Replaces the first occurence of 1 or more spaces with exactly 2 spaces.)

You could alias this to---eg---"ls2"

You can also make the number of spaces dependent on the number of digits following.

Last edited by pixellany; 11-23-2009 at 04:04 PM.
 
Old 11-23-2009, 04:09 PM   #6
valen_tino
Member
 
Registered: Jan 2008
Posts: 105

Original Poster
Rep: Reputation: 28
Aah...the sed worked like a charm. I will run it by the mainframe guys and see how that goes. If that goes well I will create the alias as you mentioned. Thanks.

Last edited by valen_tino; 11-23-2009 at 04:15 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect the output of exec command output in perl? sudhap85 Linux - Newbie 3 08-28-2009 03:35 PM
LXer: Duplicating And Modifying NetBackup Policies, Schedules And Client Via Command LXer Syndicated Linux News 0 04-07-2009 10:30 AM
Grep on output of command returns all output traigo Linux - Newbie 2 02-24-2009 05:15 PM
How do I parse the output of a command that output to standard out? gauol Programming 9 01-17-2008 01:54 PM
modifying tcpdump output sautila LinuxQuestions.org Member Intro 0 03-09-2007 06:05 PM


All times are GMT -5. The time now is 11:43 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration