how to search and replace character from middle of line
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
how to search and replace character from middle of line
Hi ,
I have one xml file which is having some lines like below
<StartDate>2008-05-07T09:45:48.000000000-05:00</StartDate>
<EndDate>2008-05-07T09:45:48.123456789-05:00</EndDate>
in above lines there is one number of 9 digits ( in blue color) . i want only first three digits out of this 9 digit and rest of the line remain uncganged .
I have one xml file which is having some lines like below
<StartDate>2008-05-07T09:45:48.000000000-05:00</StartDate>
<EndDate>2008-05-07T09:45:48.123456789-05:00</EndDate>
in above lines there is one number of 9 digits ( in blue color) . i want only first three digits out of this 9 digit and rest of the line remain uncganged .
please suggest me the solution for this
You don't say what you want to write this in. You could do it with a bash script, Perl, Python, Ruby, or pretty much any other programming language you can think of.
Suggest you play around with C, Perl, or Awk. Python has nice string handling, too, but I do not use it.
You'll want to pull these lines apart, and then re-assemble them with the characters you want replaced.
From my experience, Perl has one of the strongest string/regular expression handling facilities. If you can quantify these strings into unique fields of some type, then Awk would be a good solution. C is always a good standby, but you'll do a little more work.
is about String modification
yes use the Shell Scripting
or perhaps others like Tcl/TK
here
Quote:
Tcl/Tk is a portable scripting environment for Unix, Windows, and Macintosh.
Tcl provides a portable scripting environment for Unix, Windows, and Macintosh that supports string processing and pattern matching, native file system access, shell-like control over other programs, TCP/IP networking, timers, and event-driven I/O.
Tcl has traditional programming constructs like variables, loops, procedures, namespaces, error handling, script packages, and dynamic loading of DLLs. Tk provides portable GUIs on UNIX, Windows, and Macintosh.
A powerful widget set and the concise scripting interface to Tk make it a breeze to develop sophisticated user interfaces.
Tcl (Tool Command Language) is easy to learn and you can create a useful program in minutes! You are free to use Tcl/Tk however you wish, even in commercial applications.
I'm not sure if this is what you want; it just deletes the first three characters after the first '.' in lines starting with either <StartDate> or <EndDate>
Code:
sed '/^<StartDate>\|^<EndDate>/ s/\...././' infile > outfile
I don't want to delete first three digit out of nine , but want to keep firts three digits and want to delete rest of the six digits and keep rest of the line asitis .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.