0

I have a .csv sheet with 3 columns and 'n' number of rows.

Column1: It defines the name of the Rule. Column2: This is the schema line present in all the test files. Column3: This is the line which has to replace the schema line (column 2).

**Rule         FINDSCHEMA               REPLACESCHEMA**

BV1013_1-1  <xlink:type="simple" />   <xlink:type="simple_ars" />
BV1013_1-2  <xlink:type="simple" />   <xlink:type="simple_arg" />
BV1014-1    <xlink:type="simple" />   <xlink:type="simple_qrs" />

Basic Idea:

And then I have a folder (logs/BV*.log) which contains 8k+ .log files. These log files contains the a line (as defined in the second column of .csv, actually it is same in all the files.

What is the Aim??

I would like to write a bash script:

Step1: It should read the .csv file line by line

Step2: Based on the cell name in column 1, it should find all the files with this name from the (logs/) folder.

Step3: find the string as defined in column 2 in those files.

Step4: And replace it with the string from column3.

Any help is valuable.

  • 1
    this site is not a code writing service which is what you are asking for ... update your question with a boiled down crisp answerable desire which you have done battle on and show your work ... the question to search and replace a string using bash has many questions+answers over just google bash string search and replace – Scott Stensland Oct 28 '19 at 12:35
  • @ScottStensland: I respect your answer. I did search before positng the above question. I understood how to read .csv file using bash and how find and replace some pattern using bash as well. But, the problem is as I have a over 8k+ files, I have created a .csv files with filename, find value and replace value. Now am confused, how can I read first from, then search for that file in a directory and do rest of the stuff. I am quite confused so seeking for the help, am not expecting a whole code from this forum, but a guidence. – Manoj Kumar Oct 28 '19 at 12:48
  • in an effort to simplify the challenge one approach could be to just do the inner most portion first then wrap it with the next outer layer until each outer layer has been added ... start with your csv file having just one row and the dir of logs contain just one log file with values which will match your values from csv file ... get this working where you start with known knowns then add a few more log files and a few more csv records and manually verify everything works OK before throwing your code at the entire csv and entire dir of all log files – Scott Stensland Oct 28 '19 at 13:12
  • Thank @ScottStensland, your suggestion helped me. I end up doing this in Python. – Manoj Kumar Oct 30 '19 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.