Let\'s say we have a text file with 1000 lines.
How can we delete new line characters from line 20 to 500 (replace them with space for example)?
My try:
Here's a perl version:
my $min = 5; my $max = 10;
while () {
if ($. > $min && $. < $max) {
chomp;
$_ .= " ";
}
print;
}
__DATA__
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output:
1
2
3
4
5
6 7 8 9 10
11
12
13
14
15
It reads in DATA
(which you can set to being a filehandle or whatever your application requires), and checks the line number, $.
. While the line number is between $min
and $max
, the line ending is chomp
ed off and a space added to the end of the line; otherwise, the line is printed as-is.