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 ...
- 02-05-2010 #1Just 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
- 02-05-2010 #2Just Joined!
- Join Date
- Feb 2010
- Posts
- 8
sorry, I actually tried:
ls -lar *.txt | awk -v pwd="$PWD" '{print "$pwd"/"$8"}' > list_files.txt
- 02-05-2010 #3Linux 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 :
The slash is interpreted litterally and not as an operator if it is quoted.Code:ls -lar *.txt | awk -v vpwd="$(pwd)" '{print $vpwd"/"$8}' > list_files.txt
You would have the same result with :
i.e; without resorting to awk.Code:for f in $(ls -ar *.txt); do echo "$(pwd)/$f";done
0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 02-05-2010 #4Just 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
- 02-05-2010 #5Just Joined!
- Join Date
- Feb 2010
- Posts
- 8
Done!
I didn't know the difference between > and >>.
Thanks a bunch!
- 02-06-2010 #6Just Joined!
- Join Date
- Mar 2006
- Posts
- 29
find "$PWD" -iname "*.txt"
do the work XD


Reply With Quote
