Hello,
I am using csh to read a text file and save its words into variable $word in a foreach loop. These words have small back quotes ` as integral parts of them, for example, one word would be `abc`, another would be `xyz1` etc... These quotes are always the first and last characters of the variable $word. I need to remove these symbols and just keep abc or xyz1.
I tried this code in my csh:
set SortedID = $word
set SortedID = `echo $word | cut -d '`' -f 2`
Obviously it fails because of bad nested use of `, I should probably use an escape character in my '`', but changing it to '\`' did not work. In both cases, with or without the back slash, I get the error:
Unmatched '.
This same code does exactly what I want directly on the Linux shell, since I don't need the back cote to invoque it as I do from csh. Is there another escape character I can use? or maybe there is a different solution all together? Thanks
The fact that csh is very limited should not prevent a talented programmer from finding a solution.
Here's what I came up with: I made a perl script that takes any word and strips the back quote characters from it (using regular expression replacement). In my csh I just do this:
set SortedID = `somepath/RemoveBackQuote.pl $word`
instead of the failing:
set SortedID = `echo $word | cut -d '`' -f 2`
Thanks cfajohnson for the advise. I actually read in many places that csh is not good. I am new to Linux, the only reason I use csh is that the guy who taught me Linux also gave me some scripts in csh, and I started expanding them to write my own codes similar to what I do directly on the shell... Now my codes got too big!
Which shell do you suggest I switch to? tcsh? I'd like a script language as close as possible to direct shell commands (and if possible to csh), so that I don't suffer much learning the new tricks. Best!