Extracting a block of text from a large file using variables?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extracting a block of text from a large file using variables?
# 8  
Old 03-05-2014
Thanks for the reply @Scrutinizer,

I'm not sure about the terminology you used (think $0 = return current shell) apart from that I have next to no idea and i'm probably missing some inputs Smilie

I get the following error
Code:
awk: cmd. line:6:     A[++c}=$0
awk: cmd. line:6:          ^ syntax error
awk: cmd. line:9:     for (i=oend; i<=c-mend; i+++) print A[i]
awk: cmd. line:9:                ^ syntax error
awk: cmd. line:9:     for (i=oend; i<=c-mend; i+++) print A[i]
awk: cmd. line:9:                           ^ syntax error
awk: cmd. line:9:     for (i=oend; i<=c-mend; i+++) print A[i]
awk: cmd. line:9:                                 ^ syntax error
awk: cmd. line:9:     for (i=oend; i<=c-mend; i+++) print A[i]
awk: cmd. line:9:                                   ^ syntax error
awk: cmd. line:10:     for (i=oend; i<=c-mend; i+++) print A[i]
awk: cmd. line:10:                                             ^ unexpected newline or end of string

Warm regards, Klor

Last edited by Scrutinizer; 03-05-2014 at 09:59 AM.. Reason: code tags
# 9  
Old 03-05-2014
You're welcome. Did you copy my example? It seems to mention A[++c}=$0 instead of A[++c]=$0
This User Gave Thanks to Scrutinizer For This Post:
# 10  
Old 03-05-2014
Keen eye @Scrutinizer

Would you mind posting the parameters so I could understand and apply to future work?

It did work amazingly! and you have my thanks Smilie

Are you converting to C++ and using i and A commands?

Best Wishes,
Klor
# 11  
Old 03-06-2014
Quote:
Originally Posted by Klor
[..]
It did work amazingly! and you have my thanks Smilie
You're welcome
Quote:
Would you mind posting the parameters so I could understand and apply to future work?
What parameters do you mean? Do you mean if I could explain the script?
Quote:
Are you converting to C++ and using i and A commands?
r
Smilie, no just `ooh` and `ahh` ..
# 12  
Old 03-07-2014
Quote:
just `ooh` and `ahh` ..
I reserached that and got a song from 'Daddy Kane - oh ah , na na na na' Smilie

Yes please explain the script!
I'd have no idea how to reciprocate it in a different application.

I've got a fish, but not the knowledge of fishing ;P

Warm Regards,
Klor
# 13  
Old 03-07-2014
OK, let's see:
Code:
awk '
  $0~ostart{                                        # if the line contains what is in the variable start, in this case "ORBITAL ENERGIES"
    c=0                                             # set the counter to 0
  }
  $0~ostart,$0~mstart{                              # between lines that contain what is in variables ostart and start, 
    A[++c]=$0                                       # put the line in an Array with the line number relative to the start of this segment as index
  }
  END{     
    for(i=oend; i<=c-mend; i++) print A[i]          # at the end of the file after all is read, print between from the relative line number lend (3) to the relative last line number (c-mend)
  }
' ostart="ORBITAL ENERGIES" oend=3 \                # set the variables ostart, oend,
mstart="MULLIKEN POPULATION ANALYSIS" mend=3 file   # mstart and mend and specify the file name...

Does that help to understand the script?
This User Gave Thanks to Scrutinizer For This Post:
# 14  
Old 03-10-2014
Those are greater parameters @Scrutinizer, I've tried applying it to an enhanced script, the only difference is that I must extract before a line number so i tried

Code:
awk '
  $0~Hstart{
    c=0
  }
  $0~Hstart,$0~Lstart{
    A[++c]=$0
  }
  END{
     for (i=Hend; i<=c-Lend; i++) print A[i]
}
' Hstart="2.0000" Hend=-1 Lstart="0.0000" Lend=0 $LINE.ORBITALS > $LINE.MAKEMOL


For example the data is

Code:
2.0000
2.0000
2.0000
0.0000
0.0000
0.0000
0.0000


I'd like to extract the two 2.000s following the next 3 0.000 e.g

Code:
2.0000
[2.0000
2.0000
0.0000
0.0000
0.0000]
0.0000

The script is only providing another line in the print?

Warm regards,
Klor
:wq

Last edited by Scrutinizer; 03-10-2014 at 09:31 AM.. Reason: code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: passing shell variables through and extracting text

Hello, new to the forums and to awk. Glad to be here. :o I want to pass two shell (#!/bin/sh) variables through to awk and use them. They will determine where to start and stop text extraction. The code with the variables hard-coded in awk works fine; the same code, but with the shell... (7 Replies)
Discussion started by: bedtime
7 Replies

2. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

3. Shell Programming and Scripting

help extracting text from file

Hello I have a large file with lines beginning with 552, 553, 554, below is a small sample, I need to extract the data you can see below highlighted in bold from this file on the same location on every line and output it to a new file. Thank you in advance for any help 55201KL... (2 Replies)
Discussion started by: firefox2k2
2 Replies

4. Shell Programming and Scripting

extracting block of lines from a file

consider the input file which i am dealing with looks like this.. #cat 11.sql create table abc ( . . . ) engine=Innodb ; . . etc . . . create table UsM ( blah blah blah ) engine=Innodb ; (5 Replies)
Discussion started by: vivek d r
5 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

Extracting a portion of data from a very large tab delimited text file

Hi All I wanted to know how to effectively delete some columns in a large tab delimited file. I have a file that contains 5 columns and almost 100,000 rows 3456 f g t t 3456 g h 456 f h 4567 f g h z 345 f g 567 h j k lThis is a very large data file and tab delimited. I need... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

7. Shell Programming and Scripting

Help with splitting a large text file into smaller ones

Hi Everyone, I am using a centos 5.2 server as an sflow log collector on my network. Currently I am using inmons free sflowtool to collect the packets sent by my switches. I have a bash script running on an infinate loop to stop and start the log collection at set intervals - currently one... (2 Replies)
Discussion started by: lord_butler
2 Replies

8. 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

9. UNIX for Dummies Questions & Answers

extracting text and reusing the text to rename file

Hi, I have some ps files where I want to ectract/copy a certain number from and use that number to rename the ps file. eg: 'file.ps' contains following text: 14 (09 01 932688 0)t the text can be variable, the only fixed element is the '14 ('. The problem is that the fixed element can appear... (7 Replies)
Discussion started by: JohnDS
7 Replies

10. Shell Programming and Scripting

Parsing file and extracting the useful data block

Greetings All!! I have a very peculiar problem where I have to parse a big text file and extract useful data out of it with starting and ending block pattern matching. e.g. I have a input file like this: sample data block1 sample data start useful data end sample data block2 sample... (5 Replies)
Discussion started by: arminder
5 Replies
Login or Register to Ask a Question