LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to process utf8 text of filenames to cp/ln (http://www.linuxquestions.org/questions/linux-software-2/how-to-process-utf8-text-of-filenames-to-cp-ln-842812/)

thelordmule 11-06-2010 10:42 PM

how to process utf8 text of filenames to cp/ln
 
Hi everyone,

I have a unicode utf8 file containing filenames. I wish to process them with very basic scripts but the unicode is an issue.

A script to create symlinks to all the filenames and put them in a dir
Code:

#!/bin/bash

while read line
do
        echo "${line}"
        ln -sF "${line}" /other/references/
done < filelist.txt

filelist.txt looks like this:
Code:

/other/test1/myfile.txt
/other/test1/myfile with spaces.txt
/other/test1/myfile with spaces (2).txt
/other/test1/Απαγορευμένο.txt

Any special way to address the unicode filenames? The links do not come out right. I am using Mac OSX GNU bash 3.2.48.

thelordmule 11-07-2010 02:23 PM

unfortunately I could not find a bash based solution. It seems the unicode files are linked correctly, whereas the normal one are not. I believe it may have something to do with the newline character because the last line of the file was always linked only when there was no extra newline.

I gave up and made a python script instead
Code:

#!/usr/bin/python
import os
import sys

logfile = open(sys.argv[1], "r").readlines()
for line in logfile:
        filename=line.strip()
        os.system("ln -sF \""+filename+"\" /other/references/")

works wonderfully except for files with single quotes in their names ' '


All times are GMT -5. The time now is 05:30 AM.