Score:0

sed and quotation marks

cn flag

I get data files that contain both of these (with the commas and the quotation marks)
,"ncal",
,"NCAL",
I want to replace all occurrences of ,"ncal", with ,"NCAL",

BUT, I want to leave alone
,"Med Ofc Adm-Clncal Suppt Svcs",
(A downstream process is case sensitive.)

I tried both of these:

sed -i 's/%ncal%/%NCAL%/g' /data/userinfo.csv

sed -i 's/\”ncal\”/\”NCAL\”/g' /data/userinfo.csv

What am I missing? Your help is appreciated.

Matthias Lenmher avatar
nl flag
Did you tried to specify what is the initial (^) and end ($) point of the regular expression evaluation?
bac0n avatar
cn flag
odd quotes `”` (RIGHT DOUBLE QUOTATION MARK)
hr flag
... it should be as simple as `'s/"ncal"/"NCAL"/g'` (ordinary double quotes `"` are not special in sed, and the outer `'` single quotes protect them from the shell)
Score:1
ca flag

Possibly:
sed -re 's/([^a-zA-Z ]ncal[^a-zA-Z ])/\U\1/g' /data/userinfo.csv

no test data available

Function:
Find ncal where the character before and after is NOT in a-z nor A-Z , (note trailing space, so excluding spaces too) keep those characters as match number 1 (what is inside the first and only parentheses in the search portion of the s command, and therefore denoted as \1 in the replacement portion) and replace them with the \U => upper case version of the same.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.