Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, let's say I have a directory with a certain number of .txt files. I want to create a file where I get: myself:~/etc/etc_plus/01.txt myself:~/etc/etc_plus/02.txt and so fort for each ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8

    awk, print $PWD

    Hi,

    let's say I have a directory with a certain number of .txt files.
    I want to create a file where I get:

    myself:~/etc/etc_plus/01.txt
    myself:~/etc/etc_plus/02.txt

    and so fort for each .txt file.

    I tried

    ls -lar *.txt | awk -v pwd="$PWD" '{print "$pwd"/"$8"}'

    but it doesn't work.. any suggestion? thanks a lot

  2. #2
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8
    sorry, I actually tried:

    ls -lar *.txt | awk -v pwd="$PWD" '{print "$pwd"/"$8"}' > list_files.txt

  3. #3
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    After some experimenting and web searching about awk, it seems to me you should write this way :

    Code:
    ls -lar *.txt | awk -v vpwd="$(pwd)" '{print $vpwd"/"$8}' > list_files.txt
    The slash is interpreted litterally and not as an operator if it is quoted.

    You would have the same result with :

    Code:
    for f in $(ls -ar *.txt); do echo "$(pwd)/$f";done
    i.e; without resorting to awk.
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  4. #4
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8
    thanks a lot.

    your first solution seems to work like mine... instead of pwd I get file information, like rights, dimension, date, etc etc..

    the second solution make the job.
    nevertheless if I write a file, the last stream overwrite the previous one and at the end my file has just one file...

    for file in $(ls -ar *.txt); do
    comp=${file%.*}
    echo $comp $PWD/$file > comp.txt
    done

  5. #5
    Just Joined!
    Join Date
    Feb 2010
    Posts
    8
    Done!

    I didn't know the difference between > and >>.

    Thanks a bunch!

  6. #6
    Just Joined!
    Join Date
    Mar 2006
    Posts
    29
    find "$PWD" -iname "*.txt"
    do the work XD

Posting Permissions

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