#!/usr/bin/tcsh
setenv LC_ALL de_DE
rm /home/users0/me/master/me/LookupScripts/Sampa/*
foreach f ( /home/users0/me/master/me/LookupScripts/Tokenized/*.txt )
set g = "`basename $f .txt`"
set h = "`echo $g | tr "tokenized" "sampa"`"
cat $f | ./a4.lookup > Sampa/$h.txt
end
In /home/users0/me/master/me/LookupScripts/Tokenized/ I have some .txt files which are named randomnumber_tokenized.txt. I want to run a script on them and I want to put the output of the script to the folder Sampa/ and I want to keep randombumber_ in the file names but I want to rename the tokenized part to sampa, so that the new files look like randomnumber_sampa.txt.
Strangely though in the end the files are not called randomnumber_sampa.txt but randomnumber_samaaaaaa.txt
I suspect that it is either an issue with tcsh or it is because of the setenv command.
What am I doing wrong?
echo $f | tr "tokenized" "sampa"? – Julie Pelletier Jul 31 '16 at 04:18trtranslates one character at a time, always to one character, except if you use-dthen it translates to nothing.tr tokenized sampatranslates t to s, k to m, e to p, and all of d e i n o z to a. To replace a string with another string usesed, in this casesed s/tokenized/sampa/. Also: you say "some" filenames are_tokenized; note this loop will run./a4.lookupfor ALL*.txtfiles, but it will change the name only for_tokenizedand leave the filename unchanged for others. Finallycat $f | xis the same asx <$for<$f x. – dave_thompson_085 Jul 31 '16 at 09:04samaaaaaa– doc Jul 31 '16 at 13:38sampaaaaaa? I don't get apin the name of the output file. – doc Jul 31 '16 at 13:41sedas Dave showed you and your problem will be fixed. – Julie Pelletier Jul 31 '16 at 17:10trgives me such a weird result, because, as I said, I'd expect it to outputsampaaaaaa– doc Jul 31 '16 at 18:06ebeing repeated and therefore linked to the last character of the replacement characters. – Julie Pelletier Jul 31 '16 at 18:18trleaves unchanged characters that aren't in the first argument, so your random number and underscore are left unchanged. Characters that are in the first argument, but beyond the length of the second argument, reuse the last character fo the second argument. – dave_thompson_085 Aug 02 '16 at 05:16