Think about Loose Coupling | |
PerlMonks |
Re^3: PERL Command line to batch add filename to start of file in UTF-16leby graff (Chancellor) |
on Dec 06, 2015 at 00:10 UTC ( [id://1149485]=note: print w/replies, xml ) | Need Help?? |
If you ran something like this:
I hope you had a backup copy of those text files, so that you could start over with the original data. If you can't restore the versions of the files as they were before that command line was run, well... you've got a much harder problem now. For one thing, if the files had been pure UTF-16 before you ran that command, then they probably had a mix if utf8 (ASCII) and UTF-16 content after you ran it -- and other things may have gone wrong as well. If you can restore the original files, and if that version of the data was all pure UTF-16LE, then something like the following would do what you want: Note the following:
But again, if you now have to work from corrupted versions of the files (because you don't have a restorable backup of the originals), then there's rather more work you have to do (and it'll need fair bit more perl code -- you're not likely to solve it with one-liners on the command line). A couple other points: (1) Since you are using the "find" command, I would expect that you also have access to "xargs", so that you could use a pipeline command (which tends to be preferable in many situations), like this: (2) If this is something you do repeatedly (e.g. at regular intervals on new sets of text files), why not save the perl code as a script? (Typing the name of a script file would be less troublesome than re-typing or copy-pasting the perl code itself.)
In Section
Seekers of Perl Wisdom
|
|