Need to extract 7 characters immediately after text '19' from a large file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to extract 7 characters immediately after text '19' from a large file.
# 1  
Old 01-21-2009
Need to extract 7 characters immediately after text '19' from a large file.

Hi All!!

I have a large file containing millions of record. My purpose is to extract 7 characters immediately after text '19' from this file (including text '19') and save the result in new file.

So, my OUTPUT would be as under :

191234561
194567894
192789005
198839408
and so on.....

Please help. Thanks in advance
# 2  
Old 01-21-2009
Code:
echo "191234561"| cut -c3-
1234561

# 3  
Old 01-21-2009
Hi zaxxon!

Thanks for you quick response. But what i want is to search for '19' in input file and then save the seven character adjacent to text '19' in input file to output file.
# 4  
Old 01-21-2009
Something like this?

Code:
awk '/^19/{print substr($1,1,9)}' file > outfile

Regards
# 5  
Old 01-21-2009
Hi Franklin!

Thanks for your sir!

Above command is searching only when line starts with '19'. Please tell me how can i manipulate it to work even when '19' is present anywhere inside the line.

Thanks a lot for you help.
# 6  
Old 01-21-2009
Quote:
Originally Posted by parshant_bvcoe
Hi Franklin!

Thanks for your sir!

Above command is searching only when line starts with '19'. Please tell me how can i manipulate it to work even when '19' is present anywhere inside the line.

Thanks a lot for you help.
Code:
 awk '/19/{print substr($1,1,9)}' file > outfile

Regards
# 7  
Old 01-21-2009
Thanks Franklin!

But this is printing 7 character before text '19' and i wan to print 7 character after '19'. Please help


Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Command to extract empty field in a large UNIX file?

Hi All, I have records in unix file like below. In this file, we have empty fields from 4th Column to 22nd Column. I have some 200000 records in a file. I want to extract records only which have empty fields from 4th field to 22nd filed. This file is comma separated file. what is the unix... (2 Replies)
Discussion started by: rakeshp
2 Replies

2. Shell Programming and Scripting

Need to extract 8 characters from a large file.

Hi All!! I have a large file containing millions of records. My purpose is to extract 8 characters immediately from the given file. 222222222|ZRF|2008.pdf|2008|01/29/2009|001|B|C|C 222222222|ZRF|2009.pdf|2009|01/29/2010|001|B|C|C 222222222|ZRF|2010.pdf|2010|01/29/2011|001|B|C|C... (5 Replies)
Discussion started by: pavand
5 Replies

3. UNIX for Dummies Questions & Answers

Extract spread columns from large file

Dear all, I want to extract around 300 columns from a very large file with almost 2million columns. There are no headers, but I can find out which column numbers I want. I know I can extract with the function 'cut -f2' for example just the second column but how do I do this for such a large... (1 Reply)
Discussion started by: fndijk
1 Replies

4. Shell Programming and Scripting

Curl download zip extract large xml file

Hi i have a php script that works 100% however i don't want this to run on php because of server limits etc. Ideally if i could convert this simple php script to a shell script i can set it up to run on a cron. My mac server has curl on it. So i am assuming i should be using this to download the... (3 Replies)
Discussion started by: timgolding
3 Replies

5. Shell Programming and Scripting

splitting a large text file into paragraphs

Hello all, newbie here. I've searched the forum and found many "how to split a text file" topics but none that are what I'm looking for. I have a large text file (~15 MB) in size. It contains a variable number of "paragraphs" (for lack of a better word) that are each of variable length. A... (3 Replies)
Discussion started by: lupin..the..3rd
3 Replies

6. Shell Programming and Scripting

extract last 8 characters from a file name

Dear gurus I have several files with the following format filenameCCYYMMDD , that is the last 8 characters will be the date in CCYYMMDD format. eg FILENAME20110523 . Could anyone please put me through on how to extract only the last 8 characters from the files. I am thinking of using awk,sed... (2 Replies)
Discussion started by: erinlomo
2 Replies

7. Shell Programming and Scripting

extract characters from file name - script

trying to extract the numbers in this file name: fname="ebcdic.f0633.cmp_ebcdic.f0633.bin" fnametmp=${fname#*(V|v|F|f)} parse=${fnametmp%%(ENC|enc|CMP|cmp|BIN|bin)}} echo FLRECL=$parse result is FLRECL=0633.cmp_ebcdic.f0633 expected result FLRECL=0633 my guru is on holiday and i need... (5 Replies)
Discussion started by: mambo2523
5 Replies

8. Shell Programming and Scripting

extract unique pattern from large text file

Hi All, I am trying to extract data from a large text file , I want to extract lines which contains a five digit number followed by a hyphen , like 12345- , i tried with egrep ,eg : egrep "+" text.txt but which returns all the lines which contains any number of digits followed by hyhen ,... (19 Replies)
Discussion started by: shijujoe
19 Replies

9. Shell Programming and Scripting

Extract data from large file 80+ million records

Hello, I have got one file with more than 120+ million records(35 GB in size). I have to extract some relevant data from file based on some parameter and generate other output file. What will be the besat and fastest way to extract the ne file. sample file format :--... (2 Replies)
Discussion started by: learner16s
2 Replies

10. Shell Programming and Scripting

Performance issue in UNIX while generating .dat file from large text file

Hello Gurus, We are facing some performance issue in UNIX. If someone had faced such kind of issue in past please provide your suggestions on this . Problem Definition: /Few of load processes of our Finance Application are facing issue in UNIX when they uses a shell script having below... (19 Replies)
Discussion started by: KRAMA
19 Replies
Login or Register to Ask a Question