Copying/Extracting from line A to line B

Can any one please help me to copy file content between particualr line numbers.

One way:

root@isau02:/data/tmp/testfeld> cat infile
line 1
line 2
line 3
line 4
line 5
root@isau02:/data/tmp/testfeld> awk '/^line 2$/ {a=$0; next} {print} /^line 4$/ {print a}' infile
line 1
line 3
line 4
line 2
line 5

Edit:
Just noticed I showed how to cut & paste. If you want to have "line 2" really copied, just use this:

root@isau02:/data/tmp/testfeld> awk '/^line 2$/ {a=$0; print; next} {print} /^line 4$/ {print a}' infile
line 1
line 2
line 3
line 4
line 2
line 5

Hi,

to copy everything between line 2 and 4 (inclusive):

sed -n '2,4p' file >> new_file

HTH Chris

hope below perl give you some light

package UserFile;
sub new{
	shift;
	$file=shift;
	$data={};
	_open();
	return bless $data;
}
sub _open{
	open FH,"<$file";
}
sub _close{
	close FH;
}
# 1: exchange 2: overwrite 3: append/copy
sub pCnt{
	my($slef,$type,$l1,$l2)=(@_);
	my @arr=<FH>;
	if ($type==1) {$temp=$arr[$l1];$arr[$l1]=$arr[$l2];$arr[$l2]=$temp;} 
	if ($type==2) {$arr[$l2]=$arr[$l1];}
	if ($type==3) {for($i=$#arr+1;$i>$l2;$i--){$arr[$i]=$arr[$i-1];}$arr[$l2]=$arr[$l1];} 
	print "@arr";
	_close();
}
1