LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2004, 05:17 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910

Quote:
Originally posted by doodar
I fields aren't fixed width :( is there a switch to make it that way?
You're kidding, right?

If you're not MacOS' versions of the most basic tools suck :/


Cheers,
Tink

Last edited by Tinkster; 06-14-2004 at 05:20 PM.
 
Old 06-14-2004, 05:22 PM   #17
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
ls -lR | awk '{if ( $1 ~ /\./) print $1; else { print $5 "\t" $8 "\t" $9}}'
Works nicely except for files with spaces... I'm getting closer!
 
Old 06-14-2004, 05:24 PM   #18
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
I happened by, and thought I would offer this "brute force" method. Someone mentioned not being able to use colrm because it would whack the directory line. Then why not scoot the directory line over like so (not the prettiest command, but...):

Code:
ls -lR | grep "^\.\|^-" | sed s/^\./                                 \./ | colrm 1 33
<edit>
That sed line has 33 spaces for the replacement

Ugh... and the grep for the dash at the beginning of a line ought to have an 'l' for links or any other file-type designators you would want to include. (like grep "^\.\|^-\|^l")
</edit>

Last edited by Dark_Helmet; 06-14-2004 at 05:27 PM.
 
Old 06-14-2004, 05:29 PM   #19
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Tinkster
You're kidding, right?

If you're not MacOS' versions of the most basic tools suck :/
Unfortunately, I kid you not.
Code:
Domo:~/Desktop/test domo$ ls -lhR
total 12560
-rw-r--r--  1 domo  admin       6M 26 May 15:40 filename withspace.mp3
-rw-r--r--  1 domo  domo      344B 14 Jun 10:49 fileone.txt
-rw-r--r--  1 domo  domo        0B 14 Jun 10:07 filetwo.txt
drwxr-xr-x  5 domo  domo      170B 14 Jun 11:01 folderone
drwxr-xr-x  2 domo  domo       68B 14 Jun 10:08 foldertwo

./folderone:
total 0
-rw-r--r--  1 domo  domo  0B 14 Jun 10:08 image1.txt
-rw-r--r--  1 domo  domo  0B 14 Jun 10:08 image2.txt

./foldertwo:

Last edited by doodar; 06-14-2004 at 05:30 PM.
 
Old 06-14-2004, 05:50 PM   #20
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
ls -lR | awk '{if ( $1 ~ /\./) print $1; else { if ($1 == "total") print $1 " " $2; else { print $5 "\t" $8 "\t" $9}}}'
SPACES??? 'for' in awk maybe?
 
Old 06-14-2004, 06:00 PM   #21
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
I played around with mine some more and got this (sorry, the grep earlier was killing information you looks like you wanted).

Code:
ls -lR | sed "s/^\(\.\|t\)/                                 \1/" | colrm 1 33
Again, 33 spaces. Is that what you were looking for? Blank lines and "total" lines are preserved. Anyways, just thought I would mention it.
 
Old 06-14-2004, 06:09 PM   #22
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
not fixed width, so colrm doesn't work...
Code:
Domo:~/Desktop/test domo$ ls -lR | sed "s/^\(\.\|t\)/                                 \1/" | colrm 1 33

6 26 May 15:40 filename withspace.mp3
4 14 Jun 10:49 fileone.txt
0 14 Jun 10:07 filetwo.txt
0 14 Jun 11:01 folderone
8 14 Jun 10:08 foldertwo



n 10:08 image1.txt
n 10:08 image2.txt
 
Old 06-14-2004, 06:10 PM   #23
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
its sloppy, but:
ls -lR | awk '{if ( $1 ~ /\./) print $1; else { if ($1 == "total") print $1 " " $2; else { print $5 "\t" $6 " " $7 " " $8 "\t" $9 " " $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27 " " $28 " " }}}'

...works for files with up to 20 spaces
 
Old 06-14-2004, 06:12 PM   #24
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Ok, from the example you had posted earlier, it looked like the column widths were the same until you got to the file sizes. My apologies. If the reason the column widths are messed up is because of tabs, then it might be possible to use sed and replace them with the appropriate number of spaces. I'm afraid that's all I can think of though.
 
Old 06-14-2004, 08:29 PM   #25
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally posted by doodar
Unfortunately, I kid you not. :(
Code:
Domo:~/Desktop/test domo$ ls -lhR
total 12560
-rw-r--r--  1 domo  admin       6M 26 May 15:40 filename withspace.mp3
-rw-r--r--  1 domo  domo      344B 14 Jun 10:49 fileone.txt
-rw-r--r--  1 domo  domo        0B 14 Jun 10:07 filetwo.txt
drwxr-xr-x  5 domo  domo      170B 14 Jun 11:01 folderone
drwxr-xr-x  2 domo  domo       68B 14 Jun 10:08 foldertwo

./folderone:
total 0
-rw-r--r--  1 domo  domo  0B 14 Jun 10:08 image1.txt
-rw-r--r--  1 domo  domo  0B 14 Jun 10:08 image2.txt

./foldertwo:
My word, that is disgusting :)

You should install YellowDog Linux instead, or
SuSE for the Mac ;)


Cheers,
Tink
 
Old 06-15-2004, 04:21 PM   #26
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Tinkster
My word, that is disgusting

You should install YellowDog Linux instead, or
SuSE for the Mac


Cheers,
Tink
Haha, I know. I work in an office heavy in photoshop users. I use slackware at home.
 
Old 07-28-2004, 10:39 PM   #27
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally posted by doodar
its sloppy, but:
ls -lR | awk '{if ( $1 ~ /\./) print $1; else { if ($1 == "total") print $1 " " $2; else { print $5 "\t" $6 " " $7 " " $8 "\t" $9 " " $10 " " $11 " " $12 " " $13 " " $14 " " $15 " " $16 " " $17 " " $18 " " $19 " " $20 " " $21 " " $22 " " $23 " " $24 " " $25 " " $26 " " $27 " " $28 " " }}}'

...works for files with up to 20 spaces :D
It's been a while since I took part in this one, but the other
day I found a nice feature in awk that reminded me of your
problem :)

I noticed another potential issue with the output of your ls,
and was wondering whether on MacOS X ls also supports
ls --time-style=long-iso ... well, it's just a matter of counting,
really, and that I don't like to get some timestamps as pure
date, and others as date & time ;)

If it does, the following should make for a reasonably
"pretty" solution to your problem:

Code:
 
ls -lR | awk '{if ( $1 ~ /\./) print $1; else { if ($1 == "total") print $1 " " $2; else { printf("%12d %10s %5s ",$5,$6,$7); for(i=8; i<=NF; i++){printf("%s ",$i)};{printf("\n") }}}}'
All that just in case you're still looking for a better solution ;)


Cheers,
Tink
 
Old 07-29-2004, 12:01 PM   #28
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Tinkster
I noticed another potential issue with the output of your ls,
and was wondering whether on MacOS X ls also supports
ls --time-style=long-iso ...
Wow, it's been a while since this thread...
Thanks again, but here is the beginning of the man page for ls:

Code:
NAME
     ls -- list directory contents

SYNOPSIS
     ls [-ABCFGHLPRTWZabcdfghiklmnopqrstuwx1] [file ...]

Here's the entire manpage...
 
Old 07-29-2004, 01:47 PM   #29
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally posted by doodar
Wow, it's been a while since this thread...
Thanks again, but here is the beginning of the man page for ls:
Was a while indeed ...

MacOS-X ls sucks ;)

http://www2.yo-linux.com/cgi-bin/man.cgi?topic=ls
Code:
       --time-style=STYLE
              show times using style STYLE: full-iso, long-iso,  iso,  locale,
              +FORMAT

              FORMAT  is  interpreted  like  `date'; if FORMAT is FORMAT1<new-
              line>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to
              recent  files;  if  STYLE is prefixed with `posix-', STYLE takes
              effect only outside the POSIX locale
Oh well ... but what did you think of the change to the
awk bit? :) Now your files could have any number of
spaces ;)


Cheers,
Tink
 
Old 07-29-2004, 02:25 PM   #30
doodar
LQ Newbie
 
Registered: Jun 2004
Posts: 16

Original Poster
Rep: Reputation: 0
The awk string works tremendously, thank you. I actually ended up writing an Applescript to do what I was originally trying to do. It works on both System 9 and OS X. Running a unix command with your awk string runs way faster however, and I'm defintetly going to use your version for OS X.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI....ls (or similar command)...formatting output Basslord1124 Linux - Newbie 2 02-27-2005 06:13 PM
Via AC'97 5.1 Optical Output or Audigy 4.1 Output Nza Fedora 3 06-01-2004 08:49 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 08:17 PM
Bash Select Function: Formatting Output mooreted Linux - General 2 03-28-2004 07:26 AM
need hlp formatting output from ls test* Evan P. Programming 1 11-06-2003 09:40 PM


All times are GMT -5. The time now is 04:32 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration