Copy unmatched strings in from one file to another, bulk
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm trying to compare files from folder1 to their updated version in folder2. The files have identical names, but may have different number of strings. The strings look like:
string_1_name: "some text"
string_2_name: "some text"
.
.
string_n_name: "some text"
So I need to compare only the parts of the strings before colon - string_1_name, and then if a file1.txt from folder2 has an extra or updated string, I want to copy the full string string_1_name: "some text" and paste it into the file1.txt from folder1 but in the same location (an updated string can be in-between old strings) or replace an old string with an updated one. And then create the result file1.txt (with the same name) in folder3.
It will be great if the newly added strings in the result files were highlighted some how, colored or at least bolded.
Thanks.
command-line bash files
add a comment |
I'm trying to compare files from folder1 to their updated version in folder2. The files have identical names, but may have different number of strings. The strings look like:
string_1_name: "some text"
string_2_name: "some text"
.
.
string_n_name: "some text"
So I need to compare only the parts of the strings before colon - string_1_name, and then if a file1.txt from folder2 has an extra or updated string, I want to copy the full string string_1_name: "some text" and paste it into the file1.txt from folder1 but in the same location (an updated string can be in-between old strings) or replace an old string with an updated one. And then create the result file1.txt (with the same name) in folder3.
It will be great if the newly added strings in the result files were highlighted some how, colored or at least bolded.
Thanks.
command-line bash files
1
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:noas_no_fort: "Without a fort, there is nothing to assault."The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.
– Billy Kubr
Jul 13 '15 at 5:30
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
The filenames will be identical in both folders, ex.:file_1_english.txt. In folder2file_1_english.txtmay contain more strings than same file from folder1.
– Billy Kubr
Jul 13 '15 at 5:42
add a comment |
I'm trying to compare files from folder1 to their updated version in folder2. The files have identical names, but may have different number of strings. The strings look like:
string_1_name: "some text"
string_2_name: "some text"
.
.
string_n_name: "some text"
So I need to compare only the parts of the strings before colon - string_1_name, and then if a file1.txt from folder2 has an extra or updated string, I want to copy the full string string_1_name: "some text" and paste it into the file1.txt from folder1 but in the same location (an updated string can be in-between old strings) or replace an old string with an updated one. And then create the result file1.txt (with the same name) in folder3.
It will be great if the newly added strings in the result files were highlighted some how, colored or at least bolded.
Thanks.
command-line bash files
I'm trying to compare files from folder1 to their updated version in folder2. The files have identical names, but may have different number of strings. The strings look like:
string_1_name: "some text"
string_2_name: "some text"
.
.
string_n_name: "some text"
So I need to compare only the parts of the strings before colon - string_1_name, and then if a file1.txt from folder2 has an extra or updated string, I want to copy the full string string_1_name: "some text" and paste it into the file1.txt from folder1 but in the same location (an updated string can be in-between old strings) or replace an old string with an updated one. And then create the result file1.txt (with the same name) in folder3.
It will be great if the newly added strings in the result files were highlighted some how, colored or at least bolded.
Thanks.
command-line bash files
command-line bash files
edited Mar 24 at 8:49
Sergiy Kolodyazhnyy
75.1k9155327
75.1k9155327
asked Jul 13 '15 at 4:25
Billy KubrBilly Kubr
1
1
1
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:noas_no_fort: "Without a fort, there is nothing to assault."The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.
– Billy Kubr
Jul 13 '15 at 5:30
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
The filenames will be identical in both folders, ex.:file_1_english.txt. In folder2file_1_english.txtmay contain more strings than same file from folder1.
– Billy Kubr
Jul 13 '15 at 5:42
add a comment |
1
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:noas_no_fort: "Without a fort, there is nothing to assault."The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.
– Billy Kubr
Jul 13 '15 at 5:30
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
The filenames will be identical in both folders, ex.:file_1_english.txt. In folder2file_1_english.txtmay contain more strings than same file from folder1.
– Billy Kubr
Jul 13 '15 at 5:42
1
1
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:
noas_no_fort: "Without a fort, there is nothing to assault." The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.– Billy Kubr
Jul 13 '15 at 5:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:
noas_no_fort: "Without a fort, there is nothing to assault." The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.– Billy Kubr
Jul 13 '15 at 5:30
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
The filenames will be identical in both folders, ex.:
file_1_english.txt. In folder2 file_1_english.txt may contain more strings than same file from folder1.– Billy Kubr
Jul 13 '15 at 5:42
The filenames will be identical in both folders, ex.:
file_1_english.txt. In folder2 file_1_english.txt may contain more strings than same file from folder1.– Billy Kubr
Jul 13 '15 at 5:42
add a comment |
1 Answer
1
active
oldest
votes
try diff -u file_1.txt file_2.txt > patch1o2
then patch -p0 < patch1o2
the first command will create a file called patch1o2 containing all the difference between the two files
The second command will add in the first file the content of the difference at the same line position.
output will be a file_1.txt updated with extra lines from file_2.txt
edit 14/07/2015 :
create a bash script with a loop to analyse all files present in folder
here are an example:
FILE_1=folder_1/*.txt
for i in "$FILE_1"
do
awk -F"," '{print $1}' "$i"
done
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf likeawk -F ":" '{print $1}'
– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, whydiff -u [...]followed withpatch _p0is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?
– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
|
show 5 more comments
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f647727%2fcopy-unmatched-strings-in-from-one-file-to-another-bulk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
try diff -u file_1.txt file_2.txt > patch1o2
then patch -p0 < patch1o2
the first command will create a file called patch1o2 containing all the difference between the two files
The second command will add in the first file the content of the difference at the same line position.
output will be a file_1.txt updated with extra lines from file_2.txt
edit 14/07/2015 :
create a bash script with a loop to analyse all files present in folder
here are an example:
FILE_1=folder_1/*.txt
for i in "$FILE_1"
do
awk -F"," '{print $1}' "$i"
done
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf likeawk -F ":" '{print $1}'
– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, whydiff -u [...]followed withpatch _p0is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?
– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
|
show 5 more comments
try diff -u file_1.txt file_2.txt > patch1o2
then patch -p0 < patch1o2
the first command will create a file called patch1o2 containing all the difference between the two files
The second command will add in the first file the content of the difference at the same line position.
output will be a file_1.txt updated with extra lines from file_2.txt
edit 14/07/2015 :
create a bash script with a loop to analyse all files present in folder
here are an example:
FILE_1=folder_1/*.txt
for i in "$FILE_1"
do
awk -F"," '{print $1}' "$i"
done
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf likeawk -F ":" '{print $1}'
– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, whydiff -u [...]followed withpatch _p0is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?
– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
|
show 5 more comments
try diff -u file_1.txt file_2.txt > patch1o2
then patch -p0 < patch1o2
the first command will create a file called patch1o2 containing all the difference between the two files
The second command will add in the first file the content of the difference at the same line position.
output will be a file_1.txt updated with extra lines from file_2.txt
edit 14/07/2015 :
create a bash script with a loop to analyse all files present in folder
here are an example:
FILE_1=folder_1/*.txt
for i in "$FILE_1"
do
awk -F"," '{print $1}' "$i"
done
try diff -u file_1.txt file_2.txt > patch1o2
then patch -p0 < patch1o2
the first command will create a file called patch1o2 containing all the difference between the two files
The second command will add in the first file the content of the difference at the same line position.
output will be a file_1.txt updated with extra lines from file_2.txt
edit 14/07/2015 :
create a bash script with a loop to analyse all files present in folder
here are an example:
FILE_1=folder_1/*.txt
for i in "$FILE_1"
do
awk -F"," '{print $1}' "$i"
done
edited Jul 14 '15 at 9:59
A.B.
69.8k12172266
69.8k12172266
answered Jul 13 '15 at 5:39
green froggreen frog
658
658
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf likeawk -F ":" '{print $1}'
– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, whydiff -u [...]followed withpatch _p0is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?
– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
|
show 5 more comments
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf likeawk -F ":" '{print $1}'
– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, whydiff -u [...]followed withpatch _p0is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?
– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
That will work if I wanted to compare a whole file, but I need to compare just the names of the strings, if there are any new strings added. And then copy that added (whole) string to the original file.
– Billy Kubr
Jul 13 '15 at 5:52
then make a diff only on column1 with somethinf like
awk -F ":" '{print $1}'– green frog
Jul 13 '15 at 5:56
then make a diff only on column1 with somethinf like
awk -F ":" '{print $1}'– green frog
Jul 13 '15 at 5:56
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
How about doing it for all files in those folders?
– Billy Kubr
Jul 13 '15 at 16:22
one thing that I don't understand, why
diff -u [...] followed with patch _p0 is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?– green frog
Jul 13 '15 at 18:52
one thing that I don't understand, why
diff -u [...] followed with patch _p0 is not OK. its mean that you could have the same first column in the two files with only the second one which differ ?– green frog
Jul 13 '15 at 18:52
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
Because in this case the second column in file_1.txt gets replaced by the second column in file_2.txt
– Billy Kubr
Jul 13 '15 at 19:42
|
show 5 more comments
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f647727%2fcopy-unmatched-strings-in-from-one-file-to-another-bulk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please show an example of a filename in folder1 and its correspondent in folder2, as per how written it's hard to understand. I guess you meant " I need to compare only the parts of the strings after colon"?
– kos
Jul 13 '15 at 4:30
Not exactly, I don't care about "some text", I just care about the first part of a string, before the colon divider. Example of a string:
noas_no_fort: "Without a fort, there is nothing to assault."The text in quotes in file1.txt will be in different language, but the name of a localisation will be in both cases in english.– Billy Kubr
Jul 13 '15 at 5:30
Also, the strings are divided by 'Carriage returns'.
– Billy Kubr
Jul 13 '15 at 5:36
The filenames will be identical in both folders, ex.:
file_1_english.txt. In folder2file_1_english.txtmay contain more strings than same file from folder1.– Billy Kubr
Jul 13 '15 at 5:42