Replace 2nd occurance of a special character after nth occurance of a delimiter from
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would split the line into 3 parts (before, interesting, after). Probably you can split by the delimiters descr and Quantity. Next I will replace all the " chars in the interesting part and finally recreate the line. I do not know how can you identify such rows.
CoSince the OP has not marked this thread as "Solved," and the proposed solutions do not seem to address the OP's original question, here's another stab:
The O.P. phrased the question like this:
Quote:
Replace "Text Qualifier" character from data field in unix.
I have below string where '"'(Double Quote) should get replaced with space.
I want to identify such rows from file & would like to replace such text qualifier character from data in unix/linux.
The first part of the question is "I want to identify such rows [in the] file." Phrased that way, there is no reasonable way to answer it, since "such rows" has nowhere been defined.
The "awk" part of the line has been highlighted. The final dash, at the end, is a gawk shorthand for /dev/stdin.
The program was saved in a file called replace.gawk for testing.
The last line, {print} is there so that non-SAE lines will be printed as well as the ones converted.
The single-quote (feet) and quote (inches) characters were entered as \047 and \042 to avoid problems when the code is parsed. (The number of backslashes needed is too dependent on the source of the code - command line, program, inside other quotes, etc.)
The program could be made into a command like this:
Since the FS= and field= are passed as arguments rather than parameters, if you need to you can change those values when before different input files.
As written, all output goes to /dev/stdout. If the final line, {print} were changed to {print > out}, then placing an out=name before an input file would create the name file.
Last edited by PTrenholme; 11-01-2013 at 11:38 PM.
Reason: The final quote "$field" was (incorrectly) removed
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.