Thursday 27 September 2012

Linux: Convert File Types ( MIME)

Working on difference between .txt files :

vimdiff     httpserver_directory.txt Entire_productsxml.txt       

Commands used for Comparision:

1.vimdiff     httpserver_directory.txt  Entire_productsxml.txt   

 not  working as  MIME types are different. One is xml  and the other is text file.

2.I needed  iconv  command here  to conver the MIME types   from  text/xml   to ascii/xml
a. Do these files have  same character sets?

No.
Hint from google: http://www.google.co.in/url?sa=t&rct=j&q=iconv%3A%20conversion%20from%20%60text%2Fxml%27%20and%20to%20%60text%2Fplain%27%20are%20not%20supported%20%3F&source=web&cd=6&cad=rja&ved=0CEEQFjAF&url=http%3A%2F%2Funix.stackexchange.com%2Fquestions%2F11602%2Fhow-can-i-test-the-encoding-of-a-text-file-is-it-valid-and-what-is-it&ei=xvRjUK3_LoqHrAeD6IHYAQ&usg=AFQjCNELrZ1L4ptxCXQckmAXG67VBHdboQ
 file1: text/plain; charset=utf-8 file2: text/plain; charset=iso-8859-1

b.First see the character sets  of each file :
Command :

file -i *

 [root@blr-elorhel4x86 ndtrack]# file -i *

Entire_productsxml.txt:   text/plain; charset=us-ascii

Entire_productsxml.txt:   application/x-empty

httpserver_directory.txt:

httpsever_ouionly.txt:    text/plain; charset=us-ascii

ndtrack.ini:              text/plain; charset=utf-8

ndtrack.sh:               application/x-shellscript

run.sh:                   application/x-shellscript

c.To convert from one  format  to other format:
Command: I will use it later, because I need to  some   text parsing.

iconv -f FROM-ENCODING -t TO-ENCODING file.txt

d.How  am I doing text parsing?

I am using perl  command line to wipe off beginning spaces in the line to act on to file:

Re-learn : perl -nle '$_ =~ s/^(\w+)$/$&/g ; print  $_' Entire_productsxml.txt   

Beginning spaces in the line are not replaced. Simple, but I need to remember it.



No comments:

Post a Comment

Tweets by @sriramperumalla