Find the answer to your Linux question:
Results 1 to 9 of 9
Hi, the folders in my directory are : 01 02 03 .... 26 27 and I want to do a search between folders 23 and 24 so this is my ...
  1. #1
    Just Joined!
    Join Date
    May 2011
    Posts
    6

    zcat find from a range of folders?

    Hi, the folders in my directory are :

    01 02 03 .... 26 27 and I want to do a search between folders 23 and 24 so this is my command

    $ zcat 2[3,4]/*/ktraw_somecode*.gz |raw-extract-messages -t

    but I have no idea what to do it I am trying to look at files from 12 to 26, i tried

    $ zcat [12,26]/*/ktraw_somecode*.gz |raw-extract-messages -t
    but I got nothing

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Try
    Code:
    {12..26}
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    May 2011
    Posts
    6
    thanks it worked!!!

  4. #4
    Just Joined!
    Join Date
    May 2011
    Posts
    6
    another problem, if i want to know from 02 to 24 i typed {02..24}, but for the first 8 folders (02 to 09), I get the message

    zcat: 9/*/ktraw_somecode*.gz: No such file or directory

    why is the 0 getting dropped off?

  5. #5
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    yw.

    Just a note:
    The numbering with leading zeros is ..unfortunate.
    a) If you would have >99 folders, you would need to add zeros to existing directories.
    b) If you want to count e.g. from 1 to 14, then you would need to use some printf construct similar to
    Code:
    a=1; printf "%02d" $a
    So I would suggest to rename the 01--09 folders, if possible
    You must always face the curtain with a bow.

  6. #6
    Just Joined!
    Join Date
    May 2011
    Posts
    6
    sorry i'm extremely new to linux so I do not follow. I do not have permission to change the names of the folders, since it's on a company database, the names are after days of the month, so from 01 to 30 usually.
    So all I have permission to do is some simple cmd commands for information gathering, so I don't know how to incorporate your code into

    zcat {02..26}/*/ktraw_somecode*.gz |raw-extract-messages -t

  7. #7
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    Ah ok.
    For days, it is unlikely that they exceed 99

    What I meant is this:
    If the number of these directorys would increase (26..50..99),
    and finally go over 100, then you would need to adjust all already existing
    directorys to: 001, 002,.., 010, etc for consistency.

    But for days it is ok, although you now need a temporary variable and a loop instead of just some bash-isms.
    Which is less elegant and less performant, but at least more portable.

    Something like:
    Code:
    for a in {2..26}; do; DAY=printf "%02d" $a; zcat ${DAY}/*/ktraw_somecode*.gz |raw-extract-messages -t ;done
    Additionally, you would need to check for the existence of the directorys (not all months have 31 days, and february is a bit tricky)
    You must always face the curtain with a bow.

  8. #8
    Just Joined!
    Join Date
    May 2011
    Posts
    6
    Hi

    Thanks so much ! I have another question, what if I want to go up a level in folders, say search from 04/11 to 05/26

    I tried to zcat {04/11..05/26}/*/ktraw_somecode*.gz |raw-extract-messages -t apa
    but it didn't work

  9. #9
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,096
    The {} represents a number range. Not dates.

    While a oneliner might still be possible for this particular problem, I have the impression, that you need a more general and re-useable approach.

    I would suggest you develop a solution with a script language of your choice, like perl or python.
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...