Convert all files in current folder from UTF8 to ANSI, name unchanged.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert all files in current folder from UTF8 to ANSI, name unchanged.
# 1  
Old 09-06-2011
Convert all files in current folder from UTF8 to ANSI, name unchanged.

Asking for a Linux command line to
convert all files in current folder from UTF8 to ANSI, name unchanged.

Best Regards
Pei
# 2  
Old 09-06-2011
Technically, any ASCII characters are represented in UTF-8 as pure ASCII, 8-bits per byte, no funny encoding. If your files are pure ASCII anyway, no conversion's needed. And any characters which aren't, already have no ASCII equivalent -- they'd just be stripped out.

In other words, content -- or at least punctuation -- could be lost. Are you positive you want the originals overwritten?
Code:
for FILE in *.txt
do
        [ -f "$FILE" ] || continue

        iconv -c -f UTF8 -t ASCII "$FILE" > /tmp/$$ && cat /tmp/$$ > "$FILE"
done

rm -f /tmp/$$


Last edited by Corona688; 09-06-2011 at 03:42 PM..
# 3  
Old 09-06-2011
iconv seems not able to convert the file itself, which seems to tell, to keep the file name while converting is impossible....
# 4  
Old 09-07-2011
What difference does it make? You wanted it converted and ending up in the same file, this does that. (Against my better judgement, I might add.)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Convert to UTF8 File - Unix

All, I have several *.dat files which is created in windows (ANSI Endoing) Or PC File format, once I copy those files to unix. How can I convert those file to utf8 encoding ? I tired iconv, it says not supported Please help Thanks - S (5 Replies)
Discussion started by: Shanks
5 Replies

3. Shell Programming and Scripting

Convert decimal notation to ANSI point code notation

wondering if anyone has any thoughts to convert the below thru a shell script Convert decimal signalling point notation to ANSI point code notation There is a site that does that conversion but i need to implement the solution in a shell script.....Thoughts.... OS: Solaris 9 ... (4 Replies)
Discussion started by: aavam
4 Replies

4. Shell Programming and Scripting

Getting current folder name appended to all desired files

Hello everyone, Just registered here, I'm kinda new to Unix :o I've been trying to automate some processes with various Windows tools. I found that using unix scripts the result would be closest to my needs. So I installed Cygwin on Windows 7. My folders and files are structured like this:... (7 Replies)
Discussion started by: c_bg1
7 Replies

5. Programming

why the implementatoin of Bakery algorithm in ANSI C does not work in ANSI C

I follow the description of wiki (Lamport's bakery algorithm - Wikipedia, the free encyclopedia), then implement that algorithm in C, but it doesn't work, Starving is still here, is the implementation worry? Only print out: Thread ID: 0 START! Thread ID: 0 END! Thread ID: 0 START!... (2 Replies)
Discussion started by: sehang
2 Replies

6. Shell Programming and Scripting

How to find files in current folder only?

How do I find files in current folder only? We are on AIX 5.3, so maxdepth is not supported. I tried to do this find /dir1/dir2/dir3/dir4 -prune -type f to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files. Somehow the -prune option works for dir3 level... (7 Replies)
Discussion started by: Hangman2
7 Replies

7. Shell Programming and Scripting

Convert file from Unix - ANSI to PC - ANSI

Hi, I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this? Thanks, Sunil (0 Replies)
Discussion started by: ssmallya
0 Replies

8. UNIX for Dummies Questions & Answers

Pack current folder

How do I pack (using tar zcvf ?) the current folder inluding all files and folders ?? I need to be sure to get all files and folders/subfolders... Later I will unpack into a new folder on a new server.. Appreciate any help.. (3 Replies)
Discussion started by: WebWatch
3 Replies

9. UNIX for Dummies Questions & Answers

Convert UTF8 Format file to ANSI format

:confused: Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on... (9 Replies)
Discussion started by: rajreddy
9 Replies

10. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies
Login or Register to Ask a Question