I have a huge file. I need to find the line containing the pattern abc_x and replace its value 0.34 to 10% increased value. And then copy the entire file (with replaced values) into a new file. I am new to Tcl, please let me know how to do this. Thanks in advance.
find and replace a number inside a file in tcl
303 Views Asked by sing20 At
1
There are 1 best solutions below
Related Questions in REPLACE
- How can I replace a word in SQL but only if it is the last word in the string for a scalar-valued function?
- Replace special charachters to fix JSON
- Access and modify a specific part of a string in javascript
- How can I ensure incremental changes in deciphered messages in Python substitution cipher decoding?
- Replace nth-occurence of a string with an html tag
- Find, Replace and adjust image in PDF's using python
- Replace chars in existing column names without creating new columns
- Lua | String Pattern Replacement
- Powershell Remove part of Video filename containing Square/Round brackets and everything inside those brackets
- Replace a Link to a file per GScript in GMail
- camelcase package give error. TypeError: input.replaceAll is not a function
- How to replace NAs in R which get mode from a group
- i have to click on button using js ,unable to do it
- Input field needs to replace specific letters in a drawn word. I want to use declared input elements inside word elements
- Unable to download CSV file from web URL with runtime using python
Related Questions in TCL
- Is there a proper way to "break" out of a switch script and remain in the procedure other than wrapping in a loop?
- Tcl/TK: how to prevent screen tearing?
- Need help on _tkinter.TclError: invalid command name "<!DOCTYPE"
- Is it possible to use function pointers with critcl?
- In Tcl, why do I have to use quotes and curly braces for expr's argument when comparing two string literals?
- What are JCL Alternitives for Embeded Applications?
- sort array of floating point numbers in tcl
- TclOO metaclass classes objects and objdefine
- In Tcl, why is the string length of an empty string 1, not 0?
- exit(EXIT_FAILURE) : the Tcl C API equivalent
- How to decompress the contents of a var to another var?
- namespace ensemble create : limited scope
- why DSR is not working in FANET in NS2 using z=10.0
- anaconda search path ruins tcl package search path
- Tcl package textutil disappeared
Related Questions in REGSUB
- Trim line from beginning and after certain expression
- Tcl regsub issue
- Removing tabs from a string using either sed or awk and tcl regsub function
- Regsubbing simple matches
- Tcl string compare and replace with asterisk
- Varnish regular expression regsuball to uppercase (support Replacement Text Case Conversion)
- find and replace a number inside a file in tcl
- How to make without exception uppercase and lowercase letters in tcl regsub?
- How to set \n to a str in tcl
- How to use "regsub" or "regex" in Tcl to remove leading and trailing characters from a "start" period
- In Tcl how can I remove all zeroes to the left but the zeroes to the right should remain?
- TCL regsub uses RegEx match as index in associate array
- TCL regsub multiple special characters in one shot
- Remove null character tcl
- TCL regsub replace last / in file name
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
There are three key stages to this:
Reading the old file in.
Making the update to the data in memory.
Writing the new file out.
The first and third stages are pretty standard:
So now it's just about doing the transformation in memory. The best answer to this depends on the version of Tcl you're using. In all current production versions, it's probably best to split the data into lines and iterate over them, checking whether a line matches and, if it does, performing the transformation.
OK, in that code above,
matchesPatternandupdateLineare stand-ins for the real code, which might look like this:Composing all those pieces together gets this:
In 8.7 you'll be able to write the update more succinctly:
(Getting shorter than this would really require a RE engine that supports lookbehinds; Tcl's standard one does not.)