read from a specific pattern from one file and append it to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read from a specific pattern from one file and append it to another
# 1  
Old 04-02-2009
read from a specific pattern from one file and append it to another

Hi! Everyone,

Say this file1
--------------
line 1 51610183 420001010 0010CTCTLEDPPOO 2151610183
line 2 2151610183 420001010 0030A2TH2
line 3 2151610183 420001010 0040A2TH3
line 4 2151610183 420001010 0050A2TH4
line 5 2151610183 420001010 0060A1TD1
line 6 51610183 420001013 0010CTCTLEDPPOO 2151610183
line 7 51610183 420001013 0020A1TH1
line 8 51610183 420001013 0030A2TH2
line 9 51610183 420001013 0040A2TH3
line 10 51610183 420001013 0050A2TH4
line 11 51610183 420001013 0060A1TD1
line 12 51610183 420001013 0070A2TD2
line 13 2195410283 420001354 0010CTCTLEDPPOO 2954610183
line 14 2195410283 420001354 0020A1TH1
line 15 2195410283 420001354 0030A2TH2
line 16 2195410283 420001354 0040A2TH3
line 17 2195410283 420001354 0050A2TH4
line 18 2195410283 420001354 0060A1TD1
line 19 2195410283 420001354 0070A2TD2
line nn nnnnnnnnnn nnnnnnnnn nnnnnnnnn



I want to search in the file1 for the string '0010CTCTLEDPPOO'.
When found at line number 1, I want to append all the lines strting from line1 to the line just before the next apparance of
the string(in this example line6) to file2.
Once appendng from line 1 to line 5 is done, I want to come back to file1 again search for the next appearance for sting '0010CTCTLEDPPOO'
(in this example it is line 6) and then start appending the file2 again from line6 to line just before the next apparance of the string
'0010CTCTLEDPPOO'.(in the example it is line 13)
Likewise want to continue for the whole file1 irrespective of size.
I am facing a rare challange while writing a unix script for it.

Thanks in advance.

Regards,
Kinkar Ghosh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append a specific keyword in a text file into a new column

All, I have some sample text file(.csv) in the below format. In my actual file there are at least 100K rows. date 03/25/2016 A,B,C D,E,F date 03/26/2016 1,2,3 4,5,6 date 03/27/2016 6,4,3 4,5,6 I require the following output where in the date appeared at different locations need to... (3 Replies)
Discussion started by: ks_reddy
3 Replies

2. Shell Programming and Scripting

Obtain pattern from file; Append 1st Match

Not clear how to do so. Looking to append the 1st match of said pattern with 'OK TO REMOVE' file containing patter File1.txt RMS_QUANTITY_RT SMS_QUANTITY_RT file to search File2.txt <!-- dec=664, SMS_QUANTITY_RT --> <!-- dec=664, RMS_QUANTITY_RT --> Projected Results <!--... (3 Replies)
Discussion started by: TY718
3 Replies

3. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

4. Shell Programming and Scripting

Want it to read the file name and then append date stamp at the end of file?

I was thinking something like for i in `find . -name "*.log.Z"`; do mv $i name.log.Z or something like that? (3 Replies)
Discussion started by: xgringo
3 Replies

5. Shell Programming and Scripting

Read line from the file and append it to each row

Hi All, We have a file in the following format: 0.010000 $ ITI 11 LV2 $ 40456211 $ 0.135000 $ ITI 11 LV1 $ 40512211 $ 1.215600 $ ITI 11 ITI3 $ 41406211 $ 24/05/2014 14:05:02 0.030000 $ ITI 11 LV2 $ 40456211 $ ... (3 Replies)
Discussion started by: gauravsinghal79
3 Replies

6. Shell Programming and Scripting

Help with ksh-to read ip file & append lines to another file based on pattern match

Hi, I need help with this- input.txt : L B white X Y white A B brown M Y black Read this input file and if 3rd column is "white", then add specific lines to another file insert.txt. If 3rd column is brown, add different set of lines to insert.txt, and so on. For example, the given... (6 Replies)
Discussion started by: prashob123
6 Replies

7. UNIX for Dummies Questions & Answers

How to append portion of a file content to another file when a certain pattern is matching?

Hi ladies and gentleman.. I have two text file with me. I need to replace one of the file content to another file if one both files have a matching pattern. Example: text1.txt: ABCD 1234567,HELLO_WORLDA,HELLO_WORLDB DCBA 3456789,HELLO_WORLDE,HELLO_WORLDF text2.txt: XXXX,ABCD... (25 Replies)
Discussion started by: bananamen
25 Replies

8. Shell Programming and Scripting

sed to append on specific line in password file

I have the a group file and my ftp group line looks like this ... (3 Replies)
Discussion started by: slufoot80
3 Replies

9. Shell Programming and Scripting

Append lines for a specific pattern

Input: 09:43:46,538 INFO first text 10:45:46,538 INFO second text 11:00:46,538 INFO third more text Output: 09:43:46,538 INFO first text 10:45:46,538 INFO second text 11:00:46,538 INFO third more text The rule is to append all lines so each line contains this format... (7 Replies)
Discussion started by: chitech
7 Replies

10. Shell Programming and Scripting

How to Append the specific data to the xml file

I have an xml file data as shown below: <impl name="Nortel" is-enabled="true"> <package-mappings> <const-mapping target-state="EndPoint" target-param="cfCNDSubscribed" constant-value="true"/> <const-mapping... (2 Replies)
Discussion started by: ravi_rn
2 Replies
Login or Register to Ask a Question