Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing directory etc listings

Status
Not open for further replies.

bluefire78

Programmer
Mar 14, 2004
1
US
Hello, I'm pretty much a newbie at shell scripting. I'd like to write a script that includes some of the following actions. I'd be grateful if you can give me any pointers.

1) read into a variable the complete path to a folder; e.g.

ls foo

.
..
blahblah

---> parse /home/me/foo/blahblah into a variable which I can use. I know there is only one folder that will be returned from the ls; its name, however, is unpredictable.

2) parse the following to ensure that the file "thefile" has the lowest number, of files, inside [ ]. It will not always appear in exactly the same place in the listing, but it will always be named "thefile", and will be the only one to be named such.

docommand

Directory listing of /
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] AFOLDER

Directory listing of /AFOLDER/
d--------- 0 0 0 2048 Mar 13 2004 [ 279 02] .
d--------- 0 0 0 2048 Mar 13 2004 [ 278 02] ..
---------- 0 0 0 14336 Mar 13 2004 [ 7060 00] afile;1
---------- 0 0 0 14336 Mar 13 2004 [ 280 00] thefile;1
---------- 0 0 0 13871104 Mar 13 2004 [ 287 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [2187472 00] afile;1
---------- 0 0 0 83968 Mar 13 2004 [ 7067 00] afile;1
---------- 0 0 0 1859584 Mar 13 2004 [ 7108 00] afile;1
---------- 0 0 0 1073453056 Mar 13 2004 [ 8016 00] afile;1
---------- 0 0 0 1073618944 Mar 13 2004 [ 532163 00] afile;1
---------- 0 0 0 1073629184 Mar 13 2004 [1056391 00] afile;1
---------- 0 0 0 1073373184 Mar 13 2004 [1580624 00] afile;1
---------- 0 0 0 169451520 Mar 13 2004 [2104732 00] afile;1

---> TRUE

3) If the output of du-k gives a size greater than X, then do something. So I also need to parse the output:

du -k /afolder

27 /afolder/anotherfolder
6805648 /afolder/anotherfolder
6805676 /afolder

---> (6805676 > x) = TRUE

 
bluefire,

One option might be to look into using the find command.

If you do a man on find it will give you the details but here is a bit of information for you.

find [directory to search] -name [name of file] -size [size of file] -print

There are options for executing other commands with find as well but it may give you a simple and easy to understand solution.

HTH,

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top