On Nov 16, 2007 5:12 PM, Michael Tinsay <[EMAIL PROTECTED]> wrote: > > Hello script gurus, > > Suppose I have a text file with the content: > > FILE0 > FILE1 > FILE2 > > > Then I have three symlinks in my homedir: > > FILE0 -> /foo/bar > FILE1 -> /foobar > FILE2 -> /fubar > > > What's a good way to replace the contents of the text file (FILE0, FILE1, > and FILE2) with the corresponding symlinked files (/foo/bar, /foobar, /fubar > respectively)?
If you have the File::Slurp Perl module (I think it comes standard with v5.8) you can do a one-liner loop, as illustrated below (assuming the contents above is in the file `textfile':) $ cat >file1 hello world $ cat >file2 hello again $ cat >file3 get the fsck out, idiot! $ ln -sf file1 foo $ ln -sf file2 bar $ ln -sf file3 baz $ cat >textfile foo bar baz $ perl -pi.bak -MFile::Slurp -e's/(.*)\n/read_file($1)/e' textfile $ cat file hello world hello again get the fsck out, idiot! $ cat file.bak foo bar baz $ With this, the in-place edit also makes a backup of the textfile in case it botches. Cheers, Zakame -- Zak B. Elep || http://zakame.spunge.org [EMAIL PROTECTED] || [EMAIL PROTECTED] || [EMAIL PROTECTED] 1486 7957 454D E529 E4F1 F75E 5787 B1FD FA53 851D _________________________________________________ Philippine Linux Users' Group (PLUG) Mailing List [email protected] (#PLUG @ irc.free.net.ph) Read the Guidelines: http://linux.org.ph/lists Searchable Archives: http://archives.free.net.ph

