Sponsored Content
Top Forums Shell Programming and Scripting Grep start and end line of each segments in a file Post 302915769 by Veera_V on Thursday 4th of September 2014 02:47:22 PM
Old 09-04-2014
Hammer & Screwdriver Grep start and end line of each segments in a file

Cat file1

Code:
--------
----------
SCHEMA.TABLE1
insert-------
update-----
-------------
----------
SCHEMA.TABLE2
insert-------
update-----
-----------
------------
SCHEMA.TABLE3
insert-------
update-----
------------

grep -n SCHEMA > header_file2.txt

Code:
1: SCHEMA.TABLE1  
25:SCHEMA.TABLE2 
30:SCHEMA.TABLE3

I need to print values of each schema content to temp file.

Code:
sed -n '1,24p' file1.txt > file.tmp$$

sed -n '25,29p' file1.txt > file.tmp$$


Question is how can I get the start and ending line in the header file.so h that I can use with sed to place each table contents into file.


Code:
1: SCHEMA.TABLE1  (1-24)
25:SCHEMA.TABLE2  (25-29)
30:SCHEMA.TABLE3  (30-end)

I have below idea but its kind of making it complex. (syntax may not correct)

Code:
1:1:SCHEMA.TABLE1  
2:25:SCHEMA.TABLE2
3:30:SCHEMA.TABLE3

start=1
start1=expr `$start+1`

end=expr `head -$start1 file1 |tail-1 |cut-d':' -f2`-1  (24) 

sed '1, $end' > tmp

start=2
start1=expr `$start+1`

end=expr`head -3 $start1 |tail-1 |cut-d':' -f2`-1  (29)

sed '1, $end' > tmp


Regards,
Veera

Last edited by Corona688; 09-04-2014 at 04:24 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extract a particular start and end pattern from a line

hi In the foll example the whole text in a single line.... i want to extract text from IPTel to RTCPBase.h. want to use this acrooss the whole file Updated: IPTel\platform\core\include\RTCPBase.h \main\MWS2051_Sablime_Int\1... (7 Replies)
Discussion started by: manish205
7 Replies

2. UNIX for Dummies Questions & Answers

Lynx Grep Pattern Match 2 conditions Print from Start to End

I am working on a scraping project and I am stuck at this tiny grep pattern match. Sample text : FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. FPA List. ABC Personal Planning Catherine K. Wat Cath Wat Catherine K. Wat Catherine K. Wat IFRAME:... (8 Replies)
Discussion started by: kkiran
8 Replies

3. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

4. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

awk to count start and end keyword in a line

Hello fellow awkers and seders: need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows: echo $testvar ===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Discussion started by: ux4me
1 Replies

7. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

8. Shell Programming and Scripting

Split a file by start and end row.

I have a file which looks something as following, I would like to split to several files, The start and end of each file is 'FILE' and end with 'ASCII... ' . At the same time for each file in the first column add 100 and also second column add 100 the rest of the column as it is , see example of... (2 Replies)
Discussion started by: tk2000
2 Replies

9. Shell Programming and Scripting

Grep after - til the end of the line

Hi, i need to cat a file after # till the end of the file usually ill do cat /etc/somthing | grep -A999999 # but its not that professional thanks edit by bakunin: please use CODE-tags (or ICODE-tags) for code and data. Thank you. (9 Replies)
Discussion started by: batchenr
9 Replies

10. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies
ALTER 
TYPE(7) SQL Commands ALTER TYPE(7) NAME
ALTER TYPE - change the definition of a type SYNOPSIS
ALTER TYPE name RENAME TO new_name ALTER TYPE name OWNER TO new_owner ALTER TYPE name SET SCHEMA new_schema DESCRIPTION
ALTER TYPE changes the definition of an existing type. You must own the type to use ALTER TYPE. To change the schema of a type, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the type's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the type. How- ever, a superuser can alter ownership of any type anyway.) PARAMETERS
name The name (possibly schema-qualified) of an existing type to alter. new_name The new name for the type. new_owner The user name of the new owner of the type. new_schema The new schema for the type. EXAMPLES
To rename a data type: ALTER TYPE electronic_mail RENAME TO email; To change the owner of the type email to joe: ALTER TYPE email OWNER TO joe; To change the schema of the type email to customers: ALTER TYPE email SET SCHEMA customers; COMPATIBILITY
There is no ALTER TYPE statement in the SQL standard. SQL - Language Statements 2010-05-14 ALTER TYPE(7)
All times are GMT -4. The time now is 10:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy