Urgent, need script or command to extract lines from a huge text file

Urgent, need script or command to extract lines from a huge text file

Post by BillL » Thu, 04 Dec 2003 15:12:43



Hello ALL,

I have a huge ASCII file which contains thousands of lines and I want to
extract lines that contains a numeric character (0 to 9) at column position
5 and 75.

Is there a simple command to do this?

Thanks in advanced for any help.
Best regards,
Bill

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by John W. Krah » Thu, 04 Dec 2003 15:57:24



> I have a huge ASCII file which contains thousands of lines and I want to
> extract lines that contains a numeric character (0 to 9) at column position
> 5 and 75.

> Is there a simple command to do this?

perl -ne'print if substr($_,4,1)=~/\d/ and substr($_,74,1)=~/\d/' yourfile

John
--
use Perl;
program
fulfillment

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by Eric Moor » Thu, 04 Dec 2003 16:16:05



> Hello ALL,

> I have a huge ASCII file which contains thousands of lines and I want to
> extract lines that contains a numeric character (0 to 9) at column
> position 5 and 75.

> Is there a simple command to do this?

is this simple enough for you?

awk 'BEGIN {FS=""} $5 ~ /[0-9]/ && $75 ~/[0-9]/ { print $0 }' input.file

Eric

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by Stephane CHAZELA » Thu, 04 Dec 2003 16:32:37


2003-12-3, 17:12(+11), BillLi:

Quote:> I have a huge ASCII file which contains thousands of lines and I want to
> extract lines that contains a numeric character (0 to 9) at column position
> 5 and 75.

awk 'substr($0, 5, 1) substr($0, 75, 1) ~ /[0-9][0-9]/' < file

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by Stephane CHAZELA » Thu, 04 Dec 2003 16:49:10


2003-12-03, 08:16(+01), Eric Moors:
[...]
Quote:> is this simple enough for you?

> awk 'BEGIN {FS=""} $5 ~ /[0-9]/ && $75 ~/[0-9]/ { print $0 }' input.file

[...]

Maybe a little gawk specific.

POSIX says:

      1. If FS is a null string, the behavior is unspecified.

--
Stphane                      ["Stephane.Chazelas" at "free.fr"]

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by BillL » Thu, 04 Dec 2003 21:50:53


Hello Eric and Stephane,

Many thanks for the quick responses. Both solutions help to fix my problem.

Thanks again.
Best regards,
Bill

Quote:> Hello ALL,

> I have a huge ASCII file which contains thousands of lines and I want to
> extract lines that contains a numeric character (0 to 9) at column
position
> 5 and 75.

> Is there a simple command to do this?

> Thanks in advanced for any help.
> Best regards,
> Bill

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by William Par » Fri, 05 Dec 2003 08:13:37



> Hello Eric and Stephane,

> Many thanks for the quick responses. Both solutions help to fix my
> problem.



> > Hello ALL,

> > I have a huge ASCII file which contains thousands of lines and I
> > want to extract lines that contains a numeric character (0 to 9) at
> > column position 5 and 75.

> > Is there a simple command to do this?

> > Thanks in advanced for any help.  Best regards, Bill

You were given Awk solution.  Now for other ways...

1.  sed -n '/^.\{4\}[0-9].\{69\}[0-9]/p'

2.  awk -v FIELDWIDTHS='4 1 69 1' '$2~/[0-9]/ && $4~/[0-9]/ {print}'

3.  while read line; do
        a=`echo "$line" | cut -c 5,75`
        case "$a" in
            [0-9][0-9]) echo "$line";;
        esac
    done

4.  while read line; do
        a=${line:4:1}
        b=${line:74:1}
        case "$a$b" in
            ...
        esac
    done

--

Linux solution for data management and processing.

 
 
 

Urgent, need script or command to extract lines from a huge text file

Post by Michael Pao » Sat, 06 Dec 2003 04:10:22



Quote:> I want
to
> extract lines that contains a numeric character (0 to 9) at column
position
> 5 and 75.

grep '^....[0-9].....................................................................[0-9]'
 
 
 

1. Extracting lines from a text file that match a certain criteria to another text file

Hi,
I am novice UNIX shell programmer and would like some help. I am
trying to write a shell script that will read a text file line by
line. The task is to extract lines from the text file that meet a set
of criteria to another text file.
An example of the text file, foo2, that I am using is shown below,

0,0,"NBSC",12,"24/02/2004 15:35:34","RD","2.2"
1,1,"ORG-UNIT-TYPE","C",1,"13/03/1997 17:24:49","PO"
1,2,"ORG-UNIT-TYPE","C",2,"13/03/1997 17:24:49","Client"
1,3,"ORG-UNIT-HIST","C",3,"13/03/1997 17:24:49","PON"

The task is to look at the 3rd field of each line, and extract the
whole line if the third field matches the criteria.
The criteria is to extract all lines that have the 3rd field set to
the value of "NBSC" to a separate text file.
Similarly to extract all lines, to another separate file, that have
the 3rd field set to the value of "ORG-UNIT-HIST".
All lines with 3rd field set to, "ORG-UNIT-TYPE" are to be ignored.

The psuedo code that I have come up with so far is shown below,

while read -r rec_type
do
    NEXT=`echo ${rec_type} | cut -f 3 -d,`
    if "${NEXT}" = "NBSC" then
        write to text file1
    else
        if "${NEXT}" = "ORG-UNIT-HIST" then
           write to text file 2
        fi
    fi
done < foo2

Any help or pointers would be greatly appreciated. Thanks in
antcipation

2. Mail Server drop dead

3. Script to extract portions of text from a text file

4. redhat 5.0 on 2nd partition

5. Command line command from text file

6. Internet and Local Security?

7. Extracting lines from inside a text file (question for sed expert)

8. Compiling for different kernel versions.

9. Extract different lines from a text file

10. ksh script to analyse data in a huge text file

11. Extracting text from a file in a shell script

12. need search to match line & extract previous line

13. Extracting multiple lines OR deleting multiple lines from a file using AWK