script to separate bilingual text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to separate bilingual text file
# 1  
Old 04-21-2010
script to separate bilingual text file

Hi all

I have a bilingual text file, one language is English and another one is Assamese. I want to write English language text into one file and Assamese language text into another file. For Example-

input file is

as dsad জন gdfkghdfkghkdf hksdjhfkjsdfhk hksjdhfksdjf আনজনৰ মনত ghgj jkj uieurtier

out put file-1

as dsad gdfkghdfkghkdf hksdjhfkjsdfhk hksjdhfksdjf ghgj jkj uieurtier

output file-2

জন আনজনৰ মনত

Please help me !!!
# 2  
Old 04-21-2010
Is the input file unicode?
# 3  
Old 04-21-2010
Quote:
Originally Posted by jim mcnamara
Is the input file unicode?
yes. Assamesse text are in Unicode {UTF-8}
# 4  
Old 04-21-2010
That means each leading byte of Assamese text characters has the following bit pattern:

1110---- (highest order bit first) --- are bits used for data. not typing of characters.

This is the pattern for ASCII:
0------

The spaces present a problem because they exist in each character set.

You need a bit of C code to test bits, then write either one byte to an output stream
for ASCII or three bytes to an output stream opened for Assamese text. Since the spaces are common to both, I would write them as a newline and worrry about them later.

Lastly, convert the newlines in the two output files back into space characters after you are done.
# 5  
Old 04-21-2010
Quote:
Since the spaces are common to both, I would write them as a newline and worry about them later.

I think that writing the space to the same file as the previous (non space) byte, would eliminate this problem, as converting spaces to newlines, may introduce a problem with paragraph breaks etc.
Also is punctuation common?

I was curious as to how this problem would be solved.
# 6  
Old 04-21-2010
As jim mentioned above, all Assamese characters begin with a byte sequence that is not present in English text. So, differentiating between the two is easy enough.

From what I gathered, Assamese script uses characters that are also used in Bengali, and their Unicode range is 0x0980-0x09FF, which when encoded into UTF-8 is a range of three-byte sequences: 11100000 10100110 10000000 - 11100000 10100111 10111111 (hopefully I didn't mess that up Smilie).

The leading byte's value in that range is always 0xe0 (0340 octal, 224 decimal). We can test for its presence with AWK:
Code:
awk '/\xe0/ {print > "assamese"; next} {print > "english"}' data

Regards,
Alister

Last edited by alister; 04-21-2010 at 10:51 AM..
# 7  
Old 04-21-2010
Quote:
Originally Posted by jgt
I think that writing the space to the same file as the previous (non space) byte, would eliminate this problem, as converting spaces to newlines, may introduce a problem with paragraph breaks etc.
Also is punctuation common?

I was curious as to how this problem would be solved.
Yes sir punctuations are common?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to separate file

Hi, Could anyone help me with this please. Input file -- ant 1 2 3 4 2 3 4 56 7 dog 8 9 56 ant 2 3 4 5 cvh 6 7 8 ant 1 3 45 78 0 - Would like to split the file as soon as it encounters the word "ant" very first time. First Output file-- ant 1 2 3 4 2 3 4 56 7 dog 8 9 56 ... (2 Replies)
Discussion started by: Indra2011
2 Replies

2. UNIX for Beginners Questions & Answers

Ls to text file on separate lines

hi, I'm trying to print out the contents of a folder into a .txt file. The code I'm trying amongst variations is: ls -1 > filenames.txt but it prints them all on the same line ie. image102.bmpimage103.bmpimage104.bmpimage105.bmpimage106.bmp how can I change this? Please... (2 Replies)
Discussion started by: newbie100
2 Replies

3. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

4. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

5. Shell Programming and Scripting

Separate Text File into Two Lists Using Python

Hello, I have a pretty simple question, but I am new to Python and am trying to write a simple program. Put simply, I want to take a text file that looks like this: 11111 22222 33333 44444 55555 66666 77777 88888 and produce two lists, one containing the contents of the left column, one the... (0 Replies)
Discussion started by: Tyler_92
0 Replies

6. Shell Programming and Scripting

awk print header as text from separate file with getline

I would like to print the output beginning with a header from a seperate file like this: awk 'BEGIN{FS="_";print ((getline < "header.txt")>0)} { if (! ($0 ~ /EL/ ) print }" input.txtWhat am i doing wrong? (4 Replies)
Discussion started by: sdf
4 Replies

7. UNIX for Advanced & Expert Users

shell script to send separate mails to different users from a text file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: Code: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884... (0 Replies)
Discussion started by: giridhar276
0 Replies

8. Shell Programming and Scripting

Splitting text file into 2 separate files ??

Hi All, I am new to this forumn as well to the UNIX, I have basic knowledge of UNIX which I studied some years ago, now I have to do some shell scripting to load data into Oracle database using sqlldr utility, whcih I am able to do. I have a requirement where I need to do following operation. I... (10 Replies)
Discussion started by: shekharjchandra
10 Replies

9. Shell Programming and Scripting

Separate lines from text file

I have a text file with lot of rows like.. Action & Adventure|2012: Supernova NR|2009-11-01 00:01:00|2010-05-01 23:59:00|Active|3 Action & Adventure|50 Dead Men Walking|2010-01-05 00:01:00|2010-06-30 23:59:00|Active|3 Action & Adventure|Afterwards|2009-11-26 00:01:00|2010-03-26... (3 Replies)
Discussion started by: ramse8pc
3 Replies

10. Shell Programming and Scripting

Separate a portion of text file into another file

Hi, I have my input as follows : I have given two entries- From system Mon Aug 1 23:52:47 2005 Source !100000006!: Impact !100000005!: High Status ! 7!: New Last Name+!100000001!: First Name+ !100000003!: ... (4 Replies)
Discussion started by: srikanth_ksv
4 Replies
Login or Register to Ask a Question