The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix script to convert .csv file to.xls format moon_friend UNIX for Dummies Questions & Answers 1 12-08-2008 07:09 AM
steps to convert .pc file to .sh file in unix user71408 Shell Programming and Scripting 2 05-23-2008 03:52 AM
How to convert Unix executable file to Tiff Pet Teoh UNIX for Dummies Questions & Answers 1 09-28-2007 06:08 AM
Sample Unix script file to convert .xml to .csv srinivasaphani Shell Programming and Scripting 4 08-27-2007 11:04 AM
How to convert binary Unix file to text user12345 UNIX for Dummies Questions & Answers 5 11-10-2006 06:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-03-2009
ks_reddy ks_reddy is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 24
How to convert a .log file into .txt file under unix??

Hi Friends,

I have a .log file generated from a tool(Windows PC) which can be opened using a notepad, but when I tried to view the file in unix (cygwin on my laptop) the file type is showing as binary file, So I am unable to process the file.
I need to extract some of the selected text from the file using grep. Can any one help me to solve this problem by providing the script to convert this file to .txt file in unix itself to avoid the time waste in opening the file in windows and saving it as .txt and opening it unix and processing it further.

Find my file in the attachment. I have hundreds of file like this.
Any help in this regard is highly aprreciable.
Thanks..

-----Post Update-----

I just renamed the file to .txt extension as I am unable to upload in this forum. Don't get confuse with this. It is originally a .log extension file.
Attached Files
File Type: txt File1.txt (806 Bytes, 31 views)
  #2 (permalink)  
Old 06-03-2009
wireonfire wireonfire is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 19
I don't have problem opening it in cygwin. Looks like your file is messed up - a null character is inserted every other position (od -c File1.txt). I think the file was not generated properly.

Note, unix doesn't have the concept of file extensions. All it cares about is what is inside. Also windows and unix handle line breaks differently (windows uses 2 characters, unix 1), so you can't just copy directly a text file b/w the two. If using ftp, you'll need to use ascii mode so it will take care the conversion for you. Or, you can use the command dos2unix to convert the wrongly transfered windows text file to unix format on unix.

-----Post Update-----

tr -sd '\0' '' < File1.txt > newfile

That is how to get rid of the null characters.

To convert it to true unix format,

dos2unix newfile

-----Post Update-----

tr -sd '\0' '' < File1.txt > newfile

That is how to get rid of the null characters.

To convert it to true unix format,

dos2unix newfile
  #3 (permalink)  
Old 06-03-2009
curleb curleb is offline
Registered User
  
 

Join Date: Mar 2008
Location: Here, in my Ivory Tower...
Posts: 68
Open it in Write or change it to a .wri extension. Notepad's not smart enough to handle hex 0d chars.
  #4 (permalink)  
Old 06-04-2009
ks_reddy ks_reddy is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 24
Thanks wireonfire. The solution suggested by you using "tr" command satisfied my requirement..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0