Reading lines in a file matching a pattern

Hi,

I need to redirect the lines in a file to a different file if the character starting from 2 to 6 in the line are numerical [0-9].

Please let me know if anyone have any script to do this.

Thanks,
Ranjit

Can you give us an example set of the lines of the file.

Hi,

First of all, i would like to give you a suggestion that while you are here. try to give a example about your thread. Then it will be easy for others to understand your requirements and give you the suitable solution.

I assume your requirements as follow:

input:

a23456 line is the first line
abcd line is the second line
12345644 line is the third line
sadfjkl line is the forth line

output ( content in another file):

a23456 line is the first line
12345644 line is the third line

code:
awk '{
if (substr($0,2,5)+0==substr($0,2,5))
print
}' firstfile > secondfile

using same example

# awk 'substr($0,2,5) ~ /[0-9]+/' "file"
a23456 line is the first line
12345644 line is the third line

using Perl:

#!/usr/bin/perl
# extract_num_lines.pl
while (<>) {
    print if (m/^.\d{5}/);
}

Run this script as:

perl extract_num_lines.pl num_file > new_file

^ represents start of line
. represents a single character
\d represents a digit
\d{5} represent exactly five digits