Issue with sed used on multiple files

jil -  
 jil -
Hello,

I am trying to replace a string with another in all text files in a given directory using sed, but I'm getting this error message:

sed: cannot read /home/moi/data-limit/Lien vers data/TEST/*.txt: No such file or directory

here is the problematic command:
sed -i -e 's/S1c \/ R1c/NA/g' '/home/moi/data-limit/Lien vers data/TEST/*.txt'

thanks for your tips...

I should mention that it works if I do it file by file by specifying the filename... It doesn't seem to like the wildcard for processing all the text files in the directory.

2 answers

zipe31 Posted messages 34620 Registration date   Status Contributor Last intervention   6 501
 
Hello,

It's the spaces in the path that bother it (it = GNU/Linux) ;-(

You can either escape the spaces or quote them:
/home/moi/data-limit/Lien\ vers\ data/TEST/ *.txt /home/moi/data-limit/'Lien vers data'/TEST/ *.txt

A few tips:
- Before using the "-i" option, it's better to test without it first, or prefer "-i.bak" to ensure a backup ;-\
- When modifying multiple files at once, the "-s" option can be very useful.

--
Zen my nuggets ;-)
Do a favor for the environment, close your windows and adopt a penguin.
0
jil
 
Hi and thank you for your response, but it's strange because without space protection, with just one file, it works very well.

I might clarify that I am executing this command via the system command in the Octave software, which allows calling standard Linux commands in this program.
So, I have a kind of double constraint on special characters...

And since then, well I
0
zipe31 Posted messages 34620 Registration date   Status Contributor Last intervention   6 501
 
I might just clarify that I am executing this command via the system command in the Octave software,
This is probably the source of the problem ;-((

Perhaps try renaming the directory that has spaces in the first place?
0
jil
 
Hi, in the meantime, I resolved the issue with this:

deleteFirstCase = cstrcat("find", ' "', folder, '"',' -maxdepth 1 -name "*.txt" -type f -exec ', "sed -i -e 's/S1c \\/ R1c/NA/g' ", '{} \;'); system(deleteFirstCase);


it's a bit of a mess, I admit, but it seems to work.
0