[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash Scripting
Well, I spent a few minute with google.com and while I didn't find
the script I was thinking about, I did find a couple of other.
First at SHELLdorado - www.oase-shareware.org/shell
He has a script called tabulize which takes 2 or more spaces
and converts them to tabs. You could look at it and either
use it as is or convert it.
It's at www.oase-shareware.org/shell/scripts/cmds/tabulize.txt
Seeing that it is basically an awk command, made me think that
if you knew the column you wanted cut out, you could just
run it through awk. ie:
ls -l | awk '{ print $3 }'
The $3 is obviously the column you wanted printed out.
Good luck!
Steve
Steve Scherbinski wrote:
>
> I've seen scripts that you would run a file through and it would convert
> any number
> of consecutive spaces into a single colon (:), you could then use cut
> and change the
> field delimiter to the colon and get the fields you want no matter what
> the size. I
> believe the O'Reillys Unix Power Tools book probably has it, if not I'm
> sure it's
> around on the web somewhere. Let me see if I can find the version I
> have at work
> tomorrow. I think it's on one of my backup cd's I have their.
>
> Steve
>
> Jason Hackney wrote:
> >
> > Greetings all,
> >
> > I have been trying to create a feature in my backup script that will
> > scan my backup medium (Zip disk) and retrieve filesize and filename,
> > sorted by the oldest files first. The command `ls -rst1` seems to
> > provide just the information I seek. However, I can't seem to get the
> > info. into a workable variable(s). I've tried using the `cut` command,
> > but that is too inconsistent. I would like to be able to put the
> > filesize into one array and the filename into another array ala
> > `filesize[5] = 12391`, and `filename[5] = backup020401.bz2`. Then I
> > would do calculations based on the filesize to determine how many files
> > to delete to free up space for a recently created backup.
> >
> > I'm wearing out my O'Reilly bash book (which by the way is an excellent
> > reference, but perhaps a bit too concise for a rank beginner like
> > myself), and I must surely be overlooking something in the man pages ...
> > anyway does anyone have a better suggestion on how to make this work
> > with variable file sizes? I simply want to capture the filesizes and
> > filenames keeping them mutually dependant, but separate so calculations
> > can be performed on the filesizes. `cut` does work wonderful if the
> > filesize is consistent in that it takes up the same number of columns
> > for an entire directory listing. If I have a 1 KB file and a 1 MB file,
> > then `cut` goes out the door. Thank you in advance,
> >
> > Jason