Replacing multiple string in multiple files with awk
Dear All,
I have scripting problem that I cannot solve. I have one long comma-separated string, like this: 298.00, 299.01, 300.02, 301.03, 302.05, 303.06, 304.09, and so on. I have multiple text files, that contain a line, similiar like this: ref_t = x x I would like to replace x x in the first file with the first value of the string, so the result will be: ref_t = 298.00 298.00 Then the second file with second string, then the third, fourth, etc. Replacing single line in multipile files with a single string is working with sed, but I could not solve this issue so far. Any help will be appreciated, jnorbert |
Here's the script:
Quote:
|
1.You can copy the script right away into a file.
2.Make it executable(Use chmod). 3.Execute it. |
Hello RaviTezu,
it works! Thank you for help. best wishes |
Before offering a solution, please advise 2 things:
1. Will your string always be comma and space separated? 2. What is the format of the files being changed? ie how do we now which is to be the first file, second file, ... |
Hi grail,
Yes, the string is always comma and space separated. The order of the files is depending on their name, they share same name, but are numbered starting from 0, like this: file_0.txt, file_1.mdp, file_2.txt, etc. The number of files is always same of the length of the string. With a small modificiation of RaviTezu's script (where it prompts for the file's name, that I want to modify), I think I can automatize it fairly easily. best wishes |
Well my suggestion would be something like:
Code:
#!/bin/bash Code:
./script.sh '298.00, 299.01, 300.02, 301.03, 302.05, 303.06, 304.09' |
@grail: you meant
Code:
for (( i = 1; i <= $#; i++ )) |
Sorry ... wasn't getting late ... and yes what he said ;)
|
Quote:
|
All times are GMT -5. The time now is 12:37 PM. |