Visit Our UNIX and Linux User Community

Grep start and end line of each segments in a file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep start and end line of each segments in a file
# 1  
Old 09-04-2014
Hammer & Screwdriver Grep start and end line of each segments in a file

Cat file1


grep -n SCHEMA > header_file2.txt


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

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 h that I can use with sed to place each table contents into file.

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)


start1=expr `$start+1`

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

sed '1, $end' > tmp

start1=expr `$start+1`

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

sed '1, $end' > tmp


Last edited by Corona688; 09-04-2014 at 04:24 PM..
# 2  
Old 09-05-2014
Any other way we can do it without using awk?
# 3  
Old 09-05-2014
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.

Previous Thread | Next Thread
Test Your Knowledge in Computers #168
Difficulty: Easy
The OSI networking model uses 6 layers and the TCP/IP protocol suite uses a 4 layer model.
True or False?

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

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

Featured Tech Videos