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?

Hint from google:
 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


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

ndtrack.ini:              text/plain; charset=utf-8               application/x-shellscript                   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