It is currently Mon, 27 Jun 2022 12:33:50 GMT



 
Author Message
 Urgent, need script or command to extract lines from a huge text file
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



 Sun, 21 May 2006 14:12:43 GMT   
 Urgent, need script or command to extract lines from a huge text file

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

John
--
use Perl;
program
fulfillment



 Sun, 21 May 2006 14:57:24 GMT   
 Urgent, need script or command to extract lines from a huge text file

is this simple enough for you?

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

Eric



 Sun, 21 May 2006 15:16:05 GMT   
 Urgent, need script or command to extract lines from a huge text file
2003-12-3, 17:12(+11), BillLi:

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

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



 Sun, 21 May 2006 15:32:37 GMT   
 Urgent, need script or command to extract lines from a huge text file
2003-12-03, 08:16(+01), Eric Moors:
[...]
[...]

Maybe a little gawk specific.

POSIX says:

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

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



 Sun, 21 May 2006 15:49:10 GMT   
 Urgent, need script or command to extract lines from a huge text file
Hello Eric and Stephane,

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

Thanks again.
Best regards,
Bill
news:bqjusu$2482ap$1@ID-174003.news.uni-berlin.de...



 Sun, 21 May 2006 20:50:53 GMT   
 Urgent, need script or command to extract lines from a huge text file

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

--
William Park, Open Geometry Consulting, <opengeome...@yahoo.ca>
Linux solution for data management and processing.



 Mon, 22 May 2006 07:13:37 GMT   
 Urgent, need script or command to extract lines from a huge text file
<news:bqjusu$2482ap$1@ID-174003.news.uni-berlin.de>...

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



 Tue, 23 May 2006 03:10:22 GMT   
 
   [ 8 post ] 

Similar Threads

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

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

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

4. Extract different lines from a text file

5. Command line command from text file

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

7. Extracting text from a file in a shell script

8. replace a string in a text file through command line (shell)

9. Run one command for each line of a text file

10. how to split a very huge text file into small files


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software