Linux Script - Find, Copy, Paste and Change Text Files

Asked

Viewed 889 times

3

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

File Example:

Access.txt:

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

NewAccess.txt:

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

NewUsers.txt:

(Suzy;john)

I need help creating a script that does the following actions:

  1. Create a backup of the archive Access.txt.
  2. Search the archive Access.txt each of the file values NewAccess.txt (ex: test.arquivo.010) and copy the line referring to the first match of each criterion (from the file NewAccess.txt) for a new line and replace in the new line the user name field with each of the names in NewUsers.txt.

Desired Final Result:

Access.txt:

(rec;john;file.txt;test.arquivo.050)
(rec;Mike;file.txt;test.arquivo.010)
(snd;mary;testaaa.txt;sendt.asdttvo.100)
(rec;john;Notepad.txt;new.testetto.002)
(rec;Suzy;file.txt;test.arquivo.010)
(snd;Suzy;testaaa.txt;sendt.asdttvo.100)
(rec;john;.txt file;test.arquivo.010)
(snd;john;testaaa.txt;sendt.asdttvo.100)







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

I started trying with the following command:

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

But I need you to grep just bring me the first result of each file criteria NewAcess.txt, but I don’t know how to do it.

I really need help putting this one together script, don’t know scripts in Linux.

Thank you very much!

  • IS python or is perl?

  • @Guilhermenascimento: I think it doesn’t matter. I got the impression that anything that runs easy on Linux will do.

  • @hugomg really on linux we have many facilities (although there is the myth that it is the other way around), but in question of formulating the question it sounds to me without focus

  • It could be in any language. I don’t really know any of them. I’m starting on Linux now. I think it can be in Bash (Shell) same, Python or Perl, whatever is best for this case. Thank you!!

  • I find the suspension of this question a pity.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.