Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 04-11-2006, 01:11 PM   #1
LQ Newbie
Registered: Apr 2006
Posts: 3

Rep: Reputation: 0
Convert encoding through subdirectories?

I am trying to convert the encoding of a bunch of php files scattered over several subdirectories. (a Postnuke language pack) For the recoding part I planned to use htmlrecode, which I had been using before on files in one directory.

Since I had problems getting along with the piping (htmlrecode reads and writes to standard in/output), the author was so kind to help me with a small script for all files in one directory:

mkdir o
for s in *.html; do
	htmlrecode -IBIG5 -OUTF-8 < "$s" > o/"$s"
This will put the recoded files into a new subdirectory. This time however I had to modify files in many subdirectories, and I must modify the original file, not just copy a recoded version somewhere. So I tried this, inspired by another problem's solution:

find /directory_name -name *.php | htmlrecode -OUTF8
All php files were listed, but none was recoded. I admit I am pretty weak at pipes (never smoked), so some people will probably laugh seeing my obvious mistake. My personal guess is that htmlrecode does not get anything piped in (and out), but I cannot find a solution for this problem and would be grateful for a helpful answer...
Old 04-12-2006, 10:16 PM   #2
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
There is a similar thread about recursing into subdirectories here.

If you want to do something with find, do it like this:

find /directory_name -name *.php -exec yourcommand {} \;

The curly braces are substituted with the file name found.

Old 04-16-2006, 02:06 AM   #3
LQ Newbie
Registered: Apr 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the response! Unfortunately, the command got stuck again. But the curly brackets remined me of something - and now I finally did it.

The problem was not so much the cruise through subdirectories as more the correct piping. Htmlrecode (and probably iconv too) does not accept filenames as regular arguments, they have to be piped. Plus, input and output file may not be the same. So in the end, I solved this in two steps:

for f in `find /start_directory -name *.php`; do htmlrecode -OUTF8 < "$f" > "${f/php/phpu}"; done
for f in `find /start_directory -name *.phpu`; do mv "$f" "${f/phpu/php}"; done
The first step would convert 8859-1 PHP files to utf-8 and save the recoded ones with the extension "phpu". The second step then searches for those files and renames them back to "php", overwriting the previous ones.

I guess this can even be done in one line/step, but for the moment I'm happy it worked.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make cp ignore subdirectories? M4l3k Linux - Newbie 4 02-28-2011 01:48 PM
Makefile and subdirectories pycoucou Programming 4 08-18-2005 05:43 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 10:40 PM
Unzipping all .gz files in all subdirectories darin3200 Linux - General 10 04-24-2004 10:58 PM
email and subdirectories hiertjou123 Linux - Newbie 5 07-16-2003 02:08 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration