#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0

    While/for/for does not finish


    Howdy!
    I'm having a little trouble, and I think the answer may be painfully obvious, but it has to do with this code:

    while read a b c
    do
    for line in $a
    do
    for i in $c
    do
    z=$(ls /XXX/XXX/XXX | grep $line)
    q=$(echo $z | sed "s/$line/$i/")
    echo $q
    mv $z $q
    done
    done
    done< /XXX/XXX/XXX

    The problem is that it runs through every iteration except the very last. It finds numbers in a line, and replaces them with numbers from a different column, but for some reason when it gets to the very last number it needs to find and replace, it does nothing.

    If it makes any difference, the actual file that the columns are read from is 12 items long, and there are six files in the grep, all containing 2 of the strings in the file, but only the last does not change.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,484
    Rep Power
    1752
    That looks more complex than is needed, which is maybe not helping. I am making a few assumptions based on your previous requirements, etc.

    Now, the outer loop:
    Code:
    while read a b c 
    .
    done </XXX/XXX/XXX
    That is reading 12 values per line from a file, yes? If so, then the next loop:
    Code:
    for line in $a
    do
    done
    does nothing more than assign the value you already have ($a and) to a different variable ($line) and is, thus, really not needed!

    The inner loop
    Code:
    for i in $c
    do
    done
    will iterate over the 3rd to 12th columns of the line of the file.
    What you seem to be doing is finding a list of files that contain the value of the first column of your driving file ($a) and then renaming the found files.
    A bit more detail (an example couple of lines from the file) will be of help here.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    7
    Rep Power
    0
    No offense intended, but in every one of my posts so far you have misinterpreted what I trying to accomplish, partially because it is difficult to explain what I am trying to say, nevertheless I give no indication that I am reading 12 values per line from a file. I say in plain english the file is 12 items long. I have assertained value from one of your responses so far, and the rest I have moved on from without response because they have either belittled what I am trying to accomplish, or not been helpful at all and I cared enough not to be rude. I stated that what I was doing worked perfectly fine barring a final iteration that did not work, so what made you think that the inside for loop started on the third? Moreover, I am assigning individual values of the assigned column $a with $line and for $i and $c , as opposed to referencing the whole column, so it is not pointless. If it's perfectly ok with you, since this forum was anything but helpful, i'll find a nice reference guide or figure this problem out on my own.

    Comments on this post

    • SimonJM agrees : Good luck! But do please and try to explain and not jump down peoples' throats when what you say is not clear!

IMN logo majestic logo threadwatch logo seochat tools logo