Created
February 8, 2018 02:45
-
-
Save andreburto/8cd4455ed50403a4210b9c4f86b82924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
###################################################################### | |
# skip_lines.pl -- skips selected lines of a given file | |
# | |
# perl skip_lines.pl /path/to/file.txt 1,3,4,5 | |
# | | | | |
# script -----+ | | | |
# text file ---------------+ | | |
# comma separated line numbers ---------+ | |
# with no spaces | |
###################################################################### | |
use strict; | |
use warnings; | |
my ($file, $skip_lines) = @ARGV; | |
my $sl_cnt = 0; | |
my $rl_cnt = 0; | |
my @skip_lines = split(/,/, $skip_lines); | |
open(my $IN, $file) || die "Could not open file."; | |
LINE: while (<$IN>) { | |
$rl_cnt++; | |
foreach my $sl (@skip_lines) { if ($sl == $rl_cnt) { next LINE; } } | |
print $_; | |
} | |
close($IN); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment