Linux Script - Search, Copy, Paste and Change file values te texto [closed]

3

I have these 3 files: Access.txt : Large text file with records per row and columns separated by " ; ". < br> NewAcess.txt : List of new hits to add.
NewUsers.txt : List of new users to add.

Sample Files:

Access.txt :

  

(rec; john; file.txt; test.file.050)
  (rec; mike; file.txt; test.file.010)
  (snd; mary; testaaa.txt; sendt.asdttvo.100)
  (rec; john; notepad.txt; new.testetto.002)

NewAccess.txt :

  

(test.file.010)
  (sendt.asdttvo.100)

NewUsers.txt :

  

(suzy; john)

I need help creating a script that does the following:

  • Create a backup of the file Access.txt .
  • Search the Access.txt file for each NewAccess.txt file (eg test.arquivo.010) and copy the line for the first match of each of the criteria (from the NewAccess.txt file) to a new line and replace the user name field with each name in NewUsers.txt in the new line. li>

    Intended Final Result:

    Access.txt :

      

    (rec; john; file.txt; test.file.050)
      (rec; mike; file.txt; test.file.010)
      (snd; mary; testaaa.txt; sendt.asdttvo.100)
      (rec; john; notepad.txt; new.testetto.002)
      (rec; suzy; file.txt; test.file.010)
      (snd; suzy; testaaa.txt; sendt.asdttvo.100)
      (rec; john; file.txt; test.file.010)
      (snd; john; testaaa.txt; sendt.asdttvo.100)

    I am thinking of separating in the following steps:
    Find the matching lines and copy them to another Access_temp.txt file. Change the second column (from the 5th char ) of the new Access_temp.txt file with the name of the new users. Paste the contents of the Access_temp.txt (replaced user) file to the Access.txt file.

    I started by trying with the following command:

    grep -Fwf NewAccess.txt Access.txt > Access_temp.txt
    

    But I need grep to bring me only the first result of each criterion in the NewAcess.txt file, but I do not know how to do it.

    I need a lot of help putting this script , I do not know scripts on Linux.

    Thank you!

        
  • asked by anonymous 08.04.2015 / 20:02

    0 answers