parsed.org

Tips by tag: backup

Add a Newline to the End of a File by cygnus on Dec 31, 2005 04:09 PM

Use sed to add a newline to the end of a file (this will perform an in-place replacement and create a backup file, MYFILE.bak):

$ sed -i.bak '$G' MYFILE

Some programs, such as Emacs, will omit the trailing newline from a file unless configured to add one. Emacs can be configured to add a newline automatically.

backupcommandsconfigurationeditorsemacsin-placeline-endingsnewlinesedshell
Backup a Flickr Photo Set by mandric on Mar 05, 2007 08:19 PM

Here's a Perl script to back up a flickr photo set:

#!/usr/bin/perl -w

use Data::Dumper;
use Flickr::Photoset;
use Flickr::Photo;
use LWP::Simple;
use strict;

my $params = { api_key => 'your api key'};
my $info = {};

my $photoset = Flickr::Photoset->new($params);

# specify a photoset
if ($photoset->id({id => '72057594072478931'})) {
  my $title = $photoset->title;
  my $owner = $photoset->owner->real_name;
  my $photos = $photoset->photos;
  foreach my $p ( @$photos ) {
  my $id = $p->id;
  my $sizes = $p->sizes;
    foreach my $s (@$sizes) {
      if ( $s->{'label'} eq 'Original') {
        $info->{$id} = {
          source => $s->{'source'},
          title  => $p->title,
          server => $p->server
        };
        my $ret = getstore(
                    $s->{'source'},
                    $p->title.'_'.$id.'.jpg'
                  );
        print 'response was '.$ret.' for '.$p->title."/n";
      }
    }
  }
}
backupdownloadeditflickrperlphotos
In-place Sed Replace by xinu on Jan 12, 2005 11:54 AM

This command will replace occurrences of foo with bar in the file X in-place and create a backup of X in X.old:

$ sed -i.old "s/foo/bar/g" filename
backupcommandsin-placesedshell
RSS