Removing back quotes from string in CSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing back quotes from string in CSH
# 1  
Old 02-24-2009
Removing back quotes from string in CSH

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

Last edited by aplaydoc; 02-24-2009 at 05:39 PM..
# 2  
Old 02-24-2009
# 3  
Old 02-24-2009
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`

Works like a charm!
# 4  
Old 02-24-2009
Quote:
Originally Posted by aplaydoc
The fact that csh is very limited should not prevent a talented programmer from finding a solution.

A talented programmer would use a real programming language.
Quote:

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).

You made my point: csh just cannot do some things; you have to use another language.

In the UNIX shell, your problem can be solved trivially without using any external command, not even cut.
Quote:
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`

Works like a charm!
# 5  
Old 02-24-2009
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!
# 6  
Old 02-24-2009
Quote:
Originally Posted by aplaydoc
Which shell do you suggest I switch to? tcsh?

tcsh is essentially the same as csh when it comes to scripting, but it is much better at the command line.
Quote:
I'd like a script language as close as possible to direct shell commands (and if possible to csh)

You don't want anything close to csh for scripting.
Quote:
, so that I don't suffer much learning the new tricks. Best!

Use bash at the command line and POSIX shell for scripting. That way you use the same command syntax both at the command line and in your scripts.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing consecutive double quotes

Hi I have a .csv file and when opened in notepad looks like this gggg,nnnn,"last,first","llll""",nnn So, Here I would like the ouput as below gggg,nnnn,"last,first","llll",nnn i.e replace all two double quotes into one. How could I do that? This file is being processed by another... (5 Replies)
Discussion started by: dnat
5 Replies

2. Shell Programming and Scripting

Removing newline characters within DEL quotes.

Hi, Text file has DEL character(ASCII code 127) as quotes with comma as field delimiter. If any of the field contains new line character then I need to remove it. Please help me to achieve this. Thanks Vikram (4 Replies)
Discussion started by: Vikramhm
4 Replies

3. Shell Programming and Scripting

Removing quotes in sed

I have a file and I want to remove quotes from the word " ` " through sed command but unable to remove I am using below command sed s/"`XYZ`"/"ZXY"/g file1.txt > file2.txt But this is not working. How can we remove "`" through sed command (2 Replies)
Discussion started by: kaushik02018
2 Replies

4. Shell Programming and Scripting

Removing quotes within quotes

Hello everyone, I am working on a file with thousands of lines and instead of manually removing them I need a script to remove quotes within quotes. For example a line may have something such as this: "Hey, I was ready to go on stage or "break a leg", but I failed miserably." So I need to... (15 Replies)
Discussion started by: tastybrownies
15 Replies

5. Shell Programming and Scripting

awk : match the string and string with the quotes :

Hi all, Here is the data file: - want to match only lan3 in the output . - not lan3:1 file : OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE=""... (2 Replies)
Discussion started by: rveri
2 Replies

6. Shell Programming and Scripting

String between quotes

Hi, Need to capture a string between 1st & last quote. String can be anything like a b "c" d e Output: c a "b c" d e Output: b c a "b c" d "e" f Output: b c d e sed 's/.*"\(.*\)".*/\1/g' Above helps me to find the string between last quote. Need to find the string between 1st &... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

7. Shell Programming and Scripting

removing extra double quotes between pipe dilimeter

I have a flat file sample like this - "COURSE"|"ddddd " " dddd"|"sssddd sdsdsdsdx" dddddddd ffffff "aaaaa" dddddddd ffffff sdsdsd"|"xxxxxxx"| "COURSE"|"ffff " " bbbb"|"lllll"| The delimiter is pipe character (|) and the text are enclosed in double quotes... (5 Replies)
Discussion started by: vishalzone
5 Replies

8. Shell Programming and Scripting

AWK removing away needed double quotes.

The below code is to convert csv file to pipe delimited. It replaces comma with pipe if it is not in double quotes; If comma is in double quotes it doesnot replace the comma with a pipe. The code works fine except it eat away the double quotes in the output file. BEGIN... (6 Replies)
Discussion started by: pinnacle
6 Replies

9. UNIX for Dummies Questions & Answers

Removing double quotes in a file

Hi All, I have a tab delimited file where each of the strings have double quotes. The problem is that I have records which are in the following format: "TEXAS" ""HOUSTON"" "123" "" "2625-39-39" ""MAINE"" "" "456" "I" "3737-39-82" I would have to output... (3 Replies)
Discussion started by: kingofprussia
3 Replies

10. Shell Programming and Scripting

sed removing comma inside double quotes

I have a csv file with lines like the followings 123456,"ABC CO., LTD","XXX" 789012,"DEF LIMITED", "XXX" before I bcp this file to database, the comma in "CO.," need to be removed first. My script is cat <filename> | sed 's/"CO.,"/"CO."/g' but it doesn't work. Can anyone here able to... (2 Replies)
Discussion started by: joanneho
2 Replies
Login or Register to Ask a Question