Copy content of file in different file

Dear all,

I get a file which is probably in hexadecimal character which i have to load in oracle. oracle is unable to process the original file but when i copy the content into notepad it works fine.

How can i achieve in unix to copy content of file into .txt file instead of cp command as cp command will just copy the file itself.

Hope my doubt is clear.

I want to open the file and do select all -> copy -> past in new file without cp command.

If you mind explaining by what magic you used to open your file ( you must have no?) to copy the content in notepad ? As for us all this isnt clear... And what makes you thing you have Hexa char?

Remembering your other recent thread, I guess it might be a question of encoding, e.g. UTF16, not a file "containing hexadecimal" chars. I faintly remember windows creating UTF16 encoded files; where do your files come from?

Please ALWAYS post sample data so people can see and analyse what your problem might be!

Hello Rudic

I am not sure what is the problem with the file and i just guessed that it might have hexa decimal char. when processing the file it shows no data in oracle but when i copy the full content of file in another file then it works well. seeing the data from naked eye will not catch any issue arising from the content of the file.

below is the sample data from original file.

<EVENT_LOCATION>^M
00;"0";"---"^M
01;"1";"A-car"^M
02;"2";"B-car"^M
03;"3";"C-car"^M
04;"4";"D-car"^M
05;"5";"D1-car"^M
06;"6";"C1-car"^M
07;"7";"B1-car"^M
08;"8";"A1-car"^M
<CODE_0>^M
0000;"";""^M
<PRIORITY>^M
05;"";""^M
01;"";""^M
03;"";""^M
02;"";""^M
04;"";""^M
<EVENT>^M
31;198;"MDLF_DELTA_SIGMA_TEST_2_HCD";"COP Delta Sigma Test Error AI2";A;B;;ON;OFF;"ENV_FAULT"^M
31;185;"MDLF_ANALOG_INPUT_TEST_1_HCD";"COP Analog Input Test Error AI1";A;B;;ON;OFF;"ENV_FAULT"^M
31;171;"MDLF_No_Error_DSP2_HCD";"COP DSP2 self test passed";A;B;;ON;OFF;"ENV_FAULT"^M
31;156;"MDLF_SUP_IREF_RANGE_HCD";"COP internal error (IREF range)";A;B;;ON;OFF;"ENV_FAULT"^M
31;153;"MDLF_POWER_SUPPLY_SUP_TEST_HCD";"COP internal error (power supply test)";A;B;;ON;OFF;"ENV_FAULT"^M
31;14D;"MDLF_STACK_OVERFLOW_HCD";"COP internal error (stack overflow)";A;B;;ON;OFF;"ENV_FAULT"^M
31;14C;"MDLF_CYCTIMESUP_HCD";"COP internal error (DSP overrun)";A;B;;ON;OFF;"ENV_FAULT"^M
31;0C6;"SCU_ST_IEEPROM_ERR_HCD";"COP internal error (internal EEPROM)";A;B;;ON;OFF;"ENV_WARN"^M
31;0C1;"SCU_ST_WD_ERR_HCD";"SCU selftest: watchdog error";A;B;;ON;OFF;"ENV_WARN"^M
31;09D;"MD_BLUELIMIT_RB_AI1_2_STOP_HCD";"STOP: bluelimit counter reed band AI1/2";A;B;;ON;OFF;"ENV_TRIP"^M
31;08E;"MD_TRT_INTERVAL_EXC_HCD";"STOP: Selftest interval 2 is crossed";A;B;;ON;OFF;"ENV_TRIP"^M
31;07B;"MD_IH_RMS_MAX_4_HCD";"RMS Max 4 threshold of heat current exc";A;B;;ON;OFF;"ENV_TRIP"^M
31;072;"MD_II_RMS_MAX_3_HCD";"RMS Max 3 threshold of roof current exc";A;B;;ON;OFF;"ENV_TRIP"^M
31;05E;"MD_DI5_WHILE_MCB_HCD";"DI5 is on while MCB is on (feedback)";A;B;;ON;OFF;"ENV_TRIP"^M
2E;188;"MDLF_ANALOG_INPUT_TEST_4_HCA";"COP Analog Input Test Error AI4";A;B;;ON;OFF;"ENV_FAULT"^M

There is a system which generate this file and it comes form our network cloud.

So how did you edit your file in order to copy paste here ?

did you open the file with notepad?, If not, what do you see in notepad? ( what makes the difference ???)

It has comes to us with *.OTN extension, i opened the file in notepad and copied to another text file

Why is "oracle ... unable to process the original file"? What's the error messages and the result? What's the difference between this file and the one that "works fine"?

And, did you apply the solution to your recent problem before working with the file? The <CR> (^M, 0x0D) char might give a problem, then...

Oracle can open the file but shows null data in all the rows but when taking the length of the column then it shows there is indeed some data which looks like non printable data.

some magic happens when i copy the content into different file by selection all the data from original file.

Out team has agreed to do copy form origianl file and pput it in another file before processing.

so all i want is to read line by line from original file and write in new file line by line.

So you opened the file with notepad and saved from notepad as a .txt ? In which case RudiC may hit the pin: opening with notepad will automatically convert the content and more remove some encoding is doesnt like, I have from time to time some trouble with file utilizing different encoding, so I have writen scripts to convert to what I need, e.g. I get a file in UTF-8, only I need iso-8859-1...

You need to know what encoding is used for your file, then what is used on your box, then look at the iconv man pages for a start

Is there any way to get what encoding is been used

What be the result of applying the file command? On my system with some playing around:

file file?
file~: ASCII text
file1: ASCII text
file2: UTF-8 Unicode text
file3: Little-endian UTF-16 Unicode text
file4: ASCII text

Hi

I ran below command

tdc2solv112:kumarra# file -i ED_D_VLU______002_005_002_000_EN.oti
ED_D_VLU______002_005_002_000_EN.oti:   regular file

Didn't you say it's a .OTN file?

I said that we receive *.OTN extension file

The file -i option explicitly tells file not to investigate the contents of the file named by an operand if that file is a regular file. Why don't you leave off the -i and try the command again (as RudiC suggested)?

tdc2solv112:kumarra# file ED_D_VLU______002_005_002_000_EN.oti
ED_D_VLU______002_005_002_000_EN.oti:   commands text

What do the first twenty or thirty lines of output from the command:

od -bc ED_D_VLU______002_005_002_000_EN.oti

look like?

0000000 074 000 120 000 122 000 117 000 112 000 105 000 103 000 124 000
           <  \0   P  \0   R  \0   O  \0   J  \0   E  \0   C  \0   T  \0
0000020 076 000 015 000 012 000 042 000 126 000 114 000 125 000 042 000
           >  \0  \r  \0  \n  \0   "  \0   V  \0   L  \0   U  \0   "  \0
0000040 073 000 042 000 060 000 060 000 062 000 056 000 060 000 060 000
           ;  \0   "  \0   0  \0   0  \0   2  \0   .  \0   0  \0   0  \0
0000060 065 000 056 000 060 000 060 000 062 000 056 000 060 000 060 000
           5  \0   .  \0   0  \0   0  \0   2  \0   .  \0   0  \0   0  \0
0000100 060 000 042 000 073 000 042 000 115 000 111 000 124 000 122 000
           0  \0   "  \0   ;  \0   "  \0   M  \0   I  \0   T  \0   R  \0
0000120 101 000 103 000 040 000 124 000 104 000 123 000 042 000 073 000
           A  \0   C  \0      \0   T  \0   D  \0   S  \0   "  \0   ;  \0
0000140 101 000 105 000 105 000 106 000 073 000 060 000 063 000 106 000
           A  \0   E  \0   E  \0   F  \0   ;  \0   0  \0   3  \0   F  \0
0000160 105 000 073 000 042 000 105 000 116 000 042 000 073 000 042 000
           E  \0   ;  \0   "  \0   E  \0   N  \0   "  \0   ;  \0   "  \0
0000200 042 000 015 000 012 000 074 000 104 000 105 000 126 000 137 000
           "  \0  \r  \0  \n  \0   <  \0   D  \0   E  \0   V  \0   _  \0
0000220 101 000 104 000 104 000 122 000 105 000 123 000 123 000 076 000
           A  \0   D  \0   D  \0   R  \0   E  \0   S  \0   S  \0   >  \0
0000240 015 000 012 000 042 000 117 000 104 000 102 000 123 000 137 000
          \r  \0  \n  \0   "  \0   O  \0   D  \0   B  \0   S  \0   _  \0
0000260 103 000 106 000 107 000 042 000 073 000 061 000 062 000 070 000
           C  \0   F  \0   G  \0   "  \0   ;  \0   1  \0   2  \0   8  \0
0000300 073 000 042 000 042 000 015 000 012 000 042 000 117 000 104 000
           ;  \0   "  \0   "  \0  \r  \0  \n  \0   "  \0   O  \0   D  \0
0000320 102 000 123 000 137 000 103 000 106 000 107 000 042 000 073 000
           B  \0   S  \0   _  \0   C  \0   F  \0   G  \0   "  \0   ;  \0
0000340 061 000 062 000 071 000 073 000 042 000 042 000 015 000 012 000
           1  \0   2  \0   9  \0   ;  \0   "  \0   "  \0  \r  \0  \n  \0
0000360 074 000 120 000 103 000 114 000 076 000 015 000 012 000 062 000
           <  \0   P  \0   C  \0   L  \0   >  \0  \r  \0  \n  \0   2  \0
0000400 105 000 073 000 042 000 110 000 103 000 101 000 042 000 073 000
           E  \0   ;  \0   "  \0   H  \0   C  \0   A  \0   "  \0   ;  \0
0000420 042 000 103 000 117 000 120 000 040 000 103 000 141 000 162 000
           "  \0   C  \0   O  \0   P  \0      \0   C  \0   a  \0   r  \0
0000440 040 000 101 000 042 000 073 000 042 000 117 000 104 000 102 000
              \0   A  \0   "  \0   ;  \0   "  \0   O  \0   D  \0   B  \0
0000460 123 000 137 000 103 000 106 000 107 000 042 000 015 000 012 000
           S  \0   _  \0   C  \0   F  \0   G  \0   "  \0  \r  \0  \n  \0
0000500 067 000 103 000 073 000 042 000 104 000 104 000 042 000 073 000
           7  \0   C  \0   ;  \0   "  \0   D  \0   D  \0   "  \0   ;  \0
0000520 042 000 104 000 157 000 157 000 162 000 163 000 040 000 103 000
           "  \0   D  \0   o  \0   o  \0   r  \0   s  \0      \0   C  \0
0000540 141 000 162 000 040 000 104 000 042 000 073 000 042 000 117 000
           a  \0   r  \0      \0   D  \0   "  \0   ;  \0   "  \0   O  \0
0000560 104 000 102 000 123 000 137 000 103 000 106 000 107 000 042 000
           D  \0   B  \0   S  \0   _  \0   C  \0   F  \0   G  \0   "  \0
0000600 015 000 012 000 063 000 104 000 073 000 042 000 130 000 101 000
          \r  \0  \n  \0   3  \0   D  \0   ;  \0   "  \0   X  \0   A  \0
0000620 042 000 073 000 042 000 101 000 165 000 170 000 151 000 154 000
           "  \0   ;  \0   "  \0   A  \0   u  \0   x  \0   i  \0   l  \0
0000640 151 000 141 000 162 000 171 000 040 000 103 000 141 000 162 000
           i  \0   a  \0   r  \0   y  \0      \0   C  \0   a  \0   r  \0
0000660 040 000 101 000 042 000 073 000 042 000 117 000 104 000 102 000
              \0   A  \0   "  \0   ;  \0   "  \0   O  \0   D  \0   B  \0
0000700 123 000 137 000 103 000 106 000 107 000 042 000 015 000 012 000
           S  \0   _  \0   C  \0   F  \0   G  \0   "  \0  \r  \0  \n  \0
0000720 063 000 105 000 073 000 042 000 130 000 102 000 042 000 073 000
           3  \0   E  \0   ;  \0   "  \0   X  \0   B  \0   "  \0   ;  \0
0000740 042 000 101 000 165 000 170 000 151 000 154 000 151 000 141 000

That looks like a UTF16 little endian encoded file BUT WITHOUT the necessary leading hex FF FE ( 377 376 ). The file command shows

file3: application/octet-stream; charset=binary

or

file3: data

Is that the original file as created/downloaded or has it already been tampered with?

IT is original file, it will come like this only.
so i want to read every line and past in some other .txt file before processing