Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This is my command:

echo "Test" | sed -f <(sed -e 's/.*/s,&,gI/' mydic)  

The file mydic contains 2 columns delimited by commas (,)

a,AlphabetA  
.  
.   
.    
e,AlphabetE   
.   
.   
s,AlphabetS  
.   
t,AlphabetT   
test,testedd   
.   
.   
zebra,zebraaaa

The expect result is testedd, but I get AlphabetTAlphabetEAlphabetSAlphabetT.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
echo Test |sed -f <(sed 's/\(.*\),\(.*\)/s,\\<\1\\>,\2,gI/' mydic)

\< and \> indicate the start and end of a word, respectively.

share|improve this answer
    
That works. Thank you –  Runicer Apr 10 '12 at 16:36
add comment

You've asked it to replace "e" with "AlphabetE", which it's done correctly. I suspect you meant it to only consider whole words?

Try this:

echo "test" | sed -f <(sed -e 's/.*/s,\\<&\\>,gI/' mydic)

Edit: I noticed you had in fact dealt with the case issue.

share|improve this answer
    
Yes I meant the whole word and your command result is sed only the first alphabet. Result: AlphabetT>est –  Runicer Apr 10 '12 at 16:01
    
Ah, I see what I did wrong. Yes, @Peter has made the right adjustment. –  ams Apr 10 '12 at 19:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.