I have a long list of folders, inside every folder I have the file "log.dat". I wanted to read the value of a specific line inside this file. I saved the folders names in a file "All.txt", in the parent folder, then I ran this code:
#!/bin/bash
in=/a/b/c #path to the file All.txt
for i in $(cat $in/all.txt); do
sed -n '/price/p' ${in}/${i}/log.dat
done
This code was able to read almost all the files but for some reason, which I can't figure it out!! It was output the following error message:
/log.dat: No such file or directory #(then the path to this file)
If I run the command sed -n '/price/p' log.dat
inside the folder that output the error message. I get an answer!
PS:
The content of the file ALL.txt ( which is created by running the command ls>All.txt
in the parent folder) is as follow:
STR-548-021-01
STR-548-021-02
STR-548-022-01
STR-548-022-02
STR-548-023-01
STR-548-023-02
.
.
.
.
.
I tried to use the command "awk" instead of "sed" as follow:
awk '{ price }' ${in}/${i}/log.dat
And I got the same error message.
Can these carriage returns happen in Linux as an output for the command ls>All.txt?
find ./ -iname log.dat -print0 | sort -z | xargs -0 -L 1 sed -n '/price/p' | tee result.dat
xargs use, like that as example – MolbOrg May 01 '16 at 23:36find ./ -iname log.dat -type f -readable -print0
– MolbOrg May 01 '16 at 23:49