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

    Join Date
    Jun 2011
    Rep Power

    Read and Replace

    Read and Replace


    I think my last post was a little confusing, so I will try an post a sample this time.
    I have a script which is supposed to output two columns of a file to a different file, then take the first column, search a directory for it, and replace anything it finds with the second column. This is what I have:

    for file in /XXXX/XXXX/XXXX/I
    echo $VAR|awk '{printf "%d\n",$1}'|read NEWVAR
    awk < XXXX_table.txt '{print $1 $3}' >> var1
    for line in /XXXX/XXXX/XXXX/var1
    x=$(awk < var1 '{print $1}')
    y=$(awk < var1 '{print $2}')
    sed "s/$x/$y/g"
    echo $x
    echo $y

    The first loop is supposed to remove all of the leading zeroes in all the files in that directory as well, but I guess that is wrong too.

    Having lots of difficulty on this one, but I feel as though the answer is very simple
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Rep Power
    First problem - where does $VAR come from?
    Why are you doing that first loop which will only (once it runs correctly) ever produce a result that you can use from the last iteration.

    Let's go back to basics. You have a directory, containing files whose names follow a particular pattern. Show a couple of examples of the names. You mention the files have two columns which you wish to do some operations upon. Show a couple of examples of the content. Also, do the files contain just one line or many? If many do you want the operation to be performed on all or just some of those lines?

    Don't use awk < a_file_name '{print $1}' - use: awk '{print $1}' a_file_name

    You refer to file names ($VAR and XXXX_table.txt) without a path, then do a change directory (in a loop, which is a redundant thing to do!).
    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

IMN logo majestic logo threadwatch logo seochat tools logo