translate value from single quotes to double quotes
Hi Friends,
my question is i have a file like below test.txt empname,sal v'enk'y,200 i need out put in below format empname,sal v"enk"y,200 i tryed with tr command in the below way tr -cs ' ' ""<test.txt>test1.txt but as it is copying the data to test1.txt but their is no values with double quotes help me out of this.. thanks in advance. |
Hello there!
You can solve that problem with sed: Code:
sed -i -e "s/'/\"/g" ttests.txt Code:
cat tests.txt| tr -s [\'] [\"] > new_tests.txt Edit : added code tags. |
Please use ***[code][/code] tags*** around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
The main problem here is that the shell sees quotes as part of its syntax, and parses them before the command is run. You need to "quote the quotes", or otherwise escape them so that the values you need are passed to tr. http://mywiki.wooledge.org/Arguments http://mywiki.wooledge.org/WordSplitting http://mywiki.wooledge.org/Quotes Some key points to remember are:
See the bash man page QUOTING section for details So lets say you want to use tr to invert both types of quotes at the same time, for example. From the above, we can see that there are several options available to you. The easiest methods would probably use #5 or #6, otherwise it gets kind of tricky and less readable. Code:
Code:
sed $'y/\'"/"\'/' infile #using ansi-c quoting |
All times are GMT -5. The time now is 01:18 AM. |