On Thursday 03 June 2010 11:05, McKown, John wrote:
>In the z/OS UNIX version of the pax command, there is way to specify that
> the files being extracted (or added) are to be converted from one code page
> to a different one. One use of this is to convert from ISO8859-1 to
> IBM-1047 (EBCDIC) during the extract (or add). Is there a way to do this as
> simply in Linux? That is, translate from one code page to another during
> the tar unwind?
>
>The command in question looks like:
>
>pax -ofrom=IBM-1047,to=ISO8859-1 -wf somefile.pax ...list of files to add...
>
>I'd like to do this on Linux so that I could do a single pax command on
> z/OS, binary ftp the pax file to Linux, then unwind the pax file on Linux
> twice - once "as is" and the second time translating from EBCDIC (IBM-1047)
> to ASCII (ISO8859-1). I could do this on z/OS, but that would cost more CPU
> on z/OS, take more filesystem space to store both versions, and longer to
> ftp both versions.

I don't see those options in pax(1) on Linux, so you're stuck with doing the 
conversion after pax has extracted your files.  The iconv(1) program does 
such conversions.  With a bit of shell scripting, you can run iconv on every 
file in a directory tree, and preserve their ownership and permissions (if 
you are root).  Here's a shell function that does that.  The arguments are 
the pathname of the base of the directory tree to convert, the code page the 
files are currently in, and the code page you want to convert them into:

ConvertDirTree()
{
find "$1" -type f | while read file; do
    tmp="$file.ic$$"
    if iconv -f "$2" -t "$3" $file" > "$tmp" && \
        chown --reference="$file" "$tmp" && \
        chmod --reference="$file" "$tmp; then
            if ! mv -f "$tmp" "$file"; then
               rm -f "$tmp"
               echo >&2 "Cannot overwrite file: $file"
            fi
    else  rm -f "$tmp"
            echo >&2 "Cannot convert file: $file"
    fi
done
}

That will convert all files in the tree in-place, and give an error for each 
file that it cannot convert or does not have permission to change.  You would 
call that function like so:

    ConvertDirTree /home/mack/pax-unpack/ ISO-8859-1 IBM-1047

I haven't tested this, of course, but it looks like it should work. :-)

While writing this I see that others have mentioned iconv too.  Hopefully this 
little script snippet solves the problem of running iconv recursively on a 
directory tree.

An exercise for the reader:  Write a FilterDirTree() function that executes an 
arbitrary command on each plain file in a directory tree.  The function 
should take the command to be executed as an argument, which can be an 
arbitrary pipeline that filters its standard input to its standard output.
        - MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software
275 Grove Street · Newton, MA 02466-2272 · USA
Tel: +1.617.614.4321
Email: m...@rs.com
Web: www.rocketsoftware.com  

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to