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:
- Create a backup of the archive
Access.txt
. - Search the archive
Access.txt
each of the file valuesNewAccess.txt
(ex: test.arquivo.010) and copy the line referring to the first match of each criterion (from the fileNewAccess.txt
) for a new line and replace in the new line the user name field with each of the names inNewUsers.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 isperl
?– Guilherme Nascimento
@Guilhermenascimento: I think it doesn’t matter. I got the impression that anything that runs easy on Linux will do.
– hugomg
@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
– Guilherme Nascimento
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!!
– Marcelo
I find the suspension of this question a pity.
– JJoao