Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Extracting a block of text from a large file using variables? Post 302891080 by Klor on Monday 3rd of March 2014 06:24:04 PM
Old 03-03-2014
Thank you Mr.Singh,
I apologize that I didn't evaluate more.
The input file has many ORBITAL ENERGIES as titles which is why I used tail -1 when cutting the line number, as it is the last one I am interested in.

Also the data line will vary so sometimes i may data.2.5+4.5 ->2.9+4.9 lines, sometimes it may be 2.10+4.10->2.15+4.15 lines so the variables need to change and be integrated into the code as they won't be fixed numbers each time.

@bartus
the parameters are as followed:
#line is defined as mol1 (molecule 1) but it will soon include 3-7 names in columnic order and read the first line then the second as a loop
Anything is # is excluded for now until I can piece together a functioning script.

OBEGIN = Searching to the bottom of the file (text) and extracting the line number from this position (cut -f 1)
OEND = amount of lines until the numeric data starts (important)
therfore ORB = Starting line of important numeric data

MBEGIN = extracting the line number of the next title in the text file
MEND = How many lines until we reach the numeric data
MULL = As it is the next title we must go in reverse and take numbers away therefore MULL is the line number of final numeric data

the #awk #sed #grep afterward are my failed attempts at inputting where fixed numbers would be okay however variables don't work for some reason

the #echos were there to make certain the variables had the correct numbers.

The input file has

~18000lines of text (including 4 other ORBITAL ENERGIES and MULL titles)
ORBITAL
data
MULLIKEN POPULATION ANALYSIS
~500 lines of text

The desired output is

All Datalines,

#######I can manage the below after i extract the data lines####

inwhich I can then do the same to created variables from when
Data = 2.0000
Data = 2.0000
Data = 0.0000
Data = 0.0000
when 2 goes to 0 i will be able to extract those lines using grep

and therefore only have
data = 2.000
data = 0.000

lines in the final file therefore create a graph

Warm Regards, Jason
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
nl(1)							      General Commands Manual							     nl(1)

NAME
nl - Numbers lines in a file SYNOPSIS
nl [-b type] [-d delimiter1[delimiter2]] [-f type] [-h type] [-i number] [-l number] [-n format] [-p] [-s [separator]] [-vnumber] [-wnum- ber] [file] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: nl: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Use the following options to change the default settings. Specifies which body section lines to number. The recognized types are as fol- lows: Numbers all lines. Number only non-empty lines. Does not number any lines. Numbers only those lines containing the specified pat- tern. The full range of regular expressions is supported for pattern. The default for type is t. Uses delimiter1 and delimiter2 as the delimiters for the start of a logical page section. The default characters are : (backslash followed by a colon). You can specify either one or two characters after the -d option. If you want to use a backslash as a delimiter, enter two back- slashes (\). If you specify only one character, it is used as start of a logical page, and the end delimiter remains the default. Specifies which logical page footer lines to number. The types recognized are the same as in -b type. The default for type is n. Specifies which logical page header lines to number. The types recognized are the same as in -b type. The default for type is n. Increments logical page line numbers by number. The default is 1. Counts number blank lines as 1. You must use one or more of the "-ba", "-fa", and "-ha" options with this option for it to be effective. For example, -l3 will only number the third adjacent blank. The default is 1. Specifies format as the line numbering format. Recognized formats are as fol- lows: Left justified, leading zeroes are suppressed. Right justified, leading zeroes are suppressed (default). Right justified, leading zeroes are kept. Ignores logical page delimiters (does not restart numbering). Separates text from line numbers with the separator string. The default value of separator is a tab character. [Tru64 UNIX] If you enter -s without an argument, there is no separation between the line number and its text. Sets the initial logical page line number to number. Specifies number as the number of digits in the line number. The default value of number is 6. OPERANDS
The path name of a file in which the lines are to be numbered. If file is not specified, standard input is used. DESCRIPTION
The nl command reads file (standard input by default), numbers the lines in the input, and writes the numbered lines to standard output. In the output, nl numbers the lines on the left, according to the options you specify on the command line. The input text must be written in logical pages. Each logical page has a header, a body, and a footer section (sections can be empty). Unless you use the -p option, nl resets the line numbers at the start of each logical page. You can set line numbering options indepen- dently for the header, body, and footer sections (for example, no numbering of header and footer lines while numbering text lines only in the body). Signal the start of logical page sections with lines in file that contain nothing but the following delimiter characters (assuming the default delimiters--see the description of the -d option): Line Contents Start of ::: Header :: Body : Footer You can name only one file on the command line. You can list the options and the file name in any order. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To number only the nonblank lines, enter: nl chap1 This displays a numbered listing of chap1, numbering only the nonblank lines in the body sections. If chap1 contains no :: :, : :, or : delimiters, then the entire file is considered the body. To number all lines, enter: nl -ba chap1 This numbers all the lines in the body sections, including blank lines. This form of the nl command is adequate for most uses. To specify a different line number format, enter: nl -i10 -nrz -s:: -v10 -w4 chap1 This numbers the lines of chap1, starting with 10 (-v10) and counting by 10s (-i10). It displays four digits for each number (-w4), including leading zeroes (-nrz). The line numbers are separated from the text by two colons (-s::). For example, if chap1 contains the following text: A not-so-important note to remember: You can't kill time without injuring eternity. then the numbered listing is as follows: 0010::A not-so-important note to remember: 0020::You can't kill time without injuring eternity. Notice that the blank line was not numbered. To do this, use the -ba option as shown in Example 2. ENVIRONMENT VARIABLES
The following environment variables affect the execution of nl: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files), the behavior of classes within regular expressions, and for deciding which characters are in character class graph. Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MES- SAGES. SEE ALSO
Commands: cat(1), pr(1) Standards: standards(5) nl(1)
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy