Merge two files by condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge two files by condition
# 15  
Old 10-14-2012
Quote:
Originally Posted by mikezang
No error, but no output..
Have you tried all other solutions..?

It seems like you a are doing some typo mistake while running.
# 16  
Old 10-14-2012
What OS and version are you using?
# 17  
Old 10-14-2012
Quote:
Originally Posted by pamu
Which errors you are getting..?
Can you test it for me?
I test it a below, but no any output, I hope that I can get result as output.txt
Code:
awk 'NR==FNR&&/^\/\*/{x=$0;getline;a[x]=$0;next}/^\/\*/{x=$0;print;getline;$0=a[x]?a[x]:$0;printf $0"\n\n"}' old.txt new.txt

# 18  
Old 10-14-2012
Quote:
Originally Posted by Scrutinizer
What OS and version are you using?
Mac OS X 10.8 Mountain Lion
# 19  
Old 10-14-2012
Quote:
Originally Posted by mikezang
Can you test it for me?
I test it a below, but no any output, I hope that I can get result as output.txt
Code:
awk 'NR==FNR&&/^\/\*/{x=$0;getline;a[x]=$0;next}/^\/\*/{x=$0;print;getline;$0=a[x]?a[x]:$0;printf $0"\n\n"}' old.txt new.txt

After looking at your given input files and given dummy files. there is huge difference in it.

But it is working fine on my machine and giving output also.( although it has some junk characters in it)
It seems there is problem with your machine only.

This is what i got..

Code:
/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"AyO-ff-rBb.text" = "MainStoryboard_iPhone.strings?????????";

/* Class = "IBUIButton"; normalTitle = "Button"; ObjectID = "LyY-6Q-CCh"; */
"LyY-6Q-CCh.normalTitle" = "Button";

/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"MZF-J3-zXE.text" = "??Storyboard????";

/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"Zj6-dJ-hY4.text" = "Localized in Localizable.strings";


Last edited by pamu; 10-14-2012 at 09:09 AM..
# 20  
Old 10-14-2012
Quote:
Originally Posted by pamu
After looking at your given input files and given dummy files. there is huge difference in it.

But it is working fine on my machine and giving output also.( although it has some junk characters in it)
It seems there is problem with your machine only.

This is what i got..

Code:
/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"AyO-ff-rBb.text" = "MainStoryboard_iPhone.strings?????????";

/* Class = "IBUIButton"; normalTitle = "Button"; ObjectID = "LyY-6Q-CCh"; */
"LyY-6Q-CCh.normalTitle" = "Button";

/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"MZF-J3-zXE.text" = "??Storyboard????";

/* Class = "IBUILabel"; text = "Localized in Localizable.strings"; ObjectID = "Zj6-dJ-hY4"; */
"Zj6-dJ-hY4.text" = "Localized in Localizable.strings";

If you can do it, I think my os is Mac, so the same script can't do them same thing, what can I do next?
# 21  
Old 10-15-2012
I found why no any output, because my file is in UTF-16 format, I am not sure why Mac awk can't process UTF-16 format file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge files and generate a resume in two files

Dear Gents, Please I need your help... I need small script :) to do the following. I have a thousand of files in a folder produced daily. I need first to merge all files called. txt (0009.txt, 0010.txt, 0011.txt) and and to output a resume of all information on 2 separate files in csv... (14 Replies)
Discussion started by: jiam912
14 Replies

2. Shell Programming and Scripting

How to merge two files?

Hi Gurus, I have two files as below file1 abc cde cdd cdf file2 123 234 345 456 I want to get abc 123 cde 234 cdd 345 (3 Replies)
Discussion started by: ken6503
3 Replies

3. Shell Programming and Scripting

Checking in a directory how many files are present and basing on that merge all the files

Hi, My requirement is,there is a directory location like: :camp/current/ In this location there can be different flat files that are generated in a single day with same header and the data will be different, differentiated by timestamp, so i need to verify how many files are generated... (10 Replies)
Discussion started by: srikanth_sagi
10 Replies

4. UNIX for Dummies Questions & Answers

Merge files

Hi, I would like to know how can I merge files based on their coordinates, but mantaining the score of each file in the output file like: Note: 1st column is for chromosome, 2nd for start, 3rd for end of segment, 4th for score file1: 1 200 300 20 1 400 500 30 file2: 1 200 350 30 1... (1 Reply)
Discussion started by: fadista
1 Replies

5. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

6. Shell Programming and Scripting

Merge 2 files

Hello, i'd like a bash script to merge 2 files without duplicate lines. Example : file1 : toto titi file2 : toto tata Expected result, file3 : toto (5 Replies)
Discussion started by: Celmar
5 Replies

7. Shell Programming and Scripting

merge files

hi i have two files file1 1234567 1234678 1234679 file2 98765|jjkskk|9393|iyutr 98765|kkooo|9393|hjjjd 98765|abcvfg|9393|sskds output should be 1234567|jjkskk|9393|iyutr 1234678|kkooo|9393|hjjjd 1234679|abcvfg|9393|sskds (5 Replies)
Discussion started by: mad_man12
5 Replies

8. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies

9. Shell Programming and Scripting

how to merge these two files?

I have two files, each of them has 12 lines, fileA has 3 columns, fileB has 1 column, like the following FileA a 1 b 2 c 3 ..blabla FileB A B C ..blabla Now I am trying to put the content of fileB as column 3 of fileA, e.g. a 1 A b 2 B c 3 C (3 Replies)
Discussion started by: fedora
3 Replies

10. Shell Programming and Scripting

help in merge files

I have created these files in a particular directory a_1.txt a_2.txt ... .. a_n.txt Each file has a single line. I want to write a output file a.txt, which will have concantated value of string from all the files. which utility should i use. copy, cat or paste???? Can anyone help... (5 Replies)
Discussion started by: u263066
5 Replies
Login or Register to Ask a Question