Perl script to add Header to files

The following script will add text to the beginning of files.

Donwload here. perlheader.pdf

This is done in three steps

1) This script copies the contents of a file to local variable by slurping.

2) The necessary text that needs to be added at the beginning of the file is added.

3) Then the original contents of the file are added using the local variable.

 

 

#!/usr/bin/perl

# Filename: header.pl

# Author : A.G.Raja

# Website : agraja.wordpress.com

# License : GPL

# pass files as arguments to this script

# this script will add the header text

use strict;

use warnings;

sub addheader{

my($infile,$header)=@_;

my $text = do { local( @ARGV, $/ ) = $infile ; <> } ;

open(FILE,”>$infile”);

print FILE $header;

print FILE $text;

close FILE

}

my $argnum;

foreach $argnum (0 .. $#ARGV){

my $infile = $ARGV[$argnum];

# Edit line below to change header text

my $header = “Header line 1nHeader line 2nHeader line 3n”;

&addheader($infile,$header);

}

# chmod +x header.pl

# ./header.pl *.txt

 

Donwload here. perlheader.pdf

Multiple Windows in a Terminal

Manage multiple terminals using screen utility

[raja@AGRAJA ~]$ screen -t name_of_screen
[raja@AGRAJA ~]$ screen -t name_of_screen2 screen_no

To navigate between screens:

1) CTRL+a

2.1) Type to list available screens; use arrow keys to select

[or]

2.2) Type w to list screens on the title bar for a moment.

i) CTRL+a

ii) type screen_no (it can be 0, 1, 2 … )

To scroll within a screen

1) CTRL+a

2) ESC

3) Page-Up/Page-Down

terminal_screen.JPG