copying text from between a pattern and *


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying text from between a pattern and *
# 1  
Old 01-24-2012
copying text from between a pattern and *

Hej all,

I have a LS-DYNA keyword file which I want to extract the node coordinates from it to another file for processing and then returning the result coordinates to the same place, the structure of the file is like:

Keyword file:

Code:
 5010497    -266.6623535    -446.2596130     563.2963257
 5010498    -274.4277954    -445.9211121     563.5822144
*[pattern1]
 5010499    -275.5645447    -458.3342285     563.6612549
 5010500    -276.7005920    -470.7477722     563.7402954
 5010501    -267.6044312    -458.4466248     563.3675537
 5010502    -268.5957336    -470.5700378     563.4403687
*NODE
 6000001 -159.1540648704 -478.7520096579 487.75653651186
 6000002 -158.9804599664 -479.5466282584 496.49199617441
 6000003 -157.9281904334 -466.7641639716 489.40632299044
 6000004 -158.7528680693 -479.5607763985 505.07000114296
 6000005 -157.7571810663 -467.5291518213 501.30952006216
 6000006 -156.8389915977 -455.1779535617 489.42573046609
 6000007 -155.6315121832 -443.2604012655 487.77569721994
 6000008 -156.5003030769 -454.6935876452 501.29771569908
 6000009 -155.4453651524 -442.6695354928 496.45395342393
 6000010  -155.311839542 -442.7448479545 504.96030157146
*[pattern2]
 6000011 -160.5354845128 -481.0823776732 408.57866519693
 6000012 -159.3628761577  -471.216804985 408.65955007967
 6000013 -160.3046349254  -481.099419512 419.70877432161
 6000014  -158.363507117 -461.2539271778 408.70630286329
 6000015 -159.2810526914 -471.1568654535 419.82095014138
 6000016 -160.0251695013 -481.1488870828 430.95399615912
 6000017 -158.1777622006 -461.1817167344 419.71966386217
 6000018 -157.3068381704 -451.1262688778 408.81897831834
 6000019 -159.0678110411 -471.1665727109 431.02314267306
 6000020 -157.1688259628 -451.0543970384 419.66971758492
 6000021 -158.0422184927  -461.147518664 430.75937283482
 6000022 -156.2871768182 -440.8832026662 408.92425119944
 6000023 -156.9940571198 -451.0386776652 430.51180754719
 6000024 -156.0841830374 -440.8652934217 419.73243157362
 6000025 -155.9741877927 -440.8885007026 430.53207773956
 6000026 -206.7043484788  -637.684378854 485.18537385415
 6000027 -206.5329725728 -637.4861298685 493.63683321699
*[pattern3]
 6000028 -205.9031003847 -636.8940963162 502.45428761309
 6000029 -200.5773430142 -627.9370513636 488.82722413719
 6000030 -199.9561963563 -626.9473345439  500.9080271551

first, I want a command to copy the lines between "*node" and the next line starting with "*" (it could be with any pattern) to the coordinates file which would be like:

Coordinates.key:

Code:
 
 6000001 -159.1540648704 -478.7520096579 487.75653651186
 6000002 -158.9804599664 -479.5466282584 496.49199617441
 6000003 -157.9281904334 -466.7641639716 489.40632299044
 6000004 -158.7528680693 -479.5607763985 505.07000114296
 6000005 -157.7571810663 -467.5291518213 501.30952006216
 6000006 -156.8389915977 -455.1779535617 489.42573046609
 6000007 -155.6315121832 -443.2604012655 487.77569721994
 6000008 -156.5003030769 -454.6935876452 501.29771569908
 6000009 -155.4453651524 -442.6695354928 496.45395342393
 6000010  -155.311839542 -442.7448479545 504.96030157146

and then I would do process on these coordinates and then I need another command to bring the new content of the Coordinates.key to the
Keyword file and overwrite it on the content between "*node" and the next line starting with '*'

I'm doing some transformations with Octave on the coordiantes and now I'm copy pasting the coordinates by hand, if you please help me about this, would be very great.

tnx
# 2  
Old 01-24-2012
Get the init Coordinates.key:
Code:
sed -n '/\*NODE/,/\*/p' infile > Coordinates.key

But not sure, how many NODE sessions in Coordinates.key.
This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 01-25-2012
Quote:
Originally Posted by rdcwayx
Get the init Coordinates.key:
Code:
sed -n '/\*NODE/,/\*/p' infile > Coordinates.key

But not sure, how many NODE sessions in Coordinates.key.
Thanks, there would be just one node session in coordinates.key and i want to bring back the new calculated numbers to the keyword file, between *node and the first star after it.

---------- Post updated at 07:19 AM ---------- Previous update was at 07:09 AM ----------

Actually the coordinates.key is like shown above and there would be no * or anything else and the whole file should be copied back, exactly the reverse action of the above command.
Tnx
# 4  
Old 01-25-2012
Code:
awk '/\*NODE/{t=1;next} /\*/{t=0} t' infile > Coordinates.key

After update the Coordinates.key, run below command:

Code:
awk '/\*NODE/{t=1;print;next} /\*/{t=0} t {getline < "Coordinates.key"}1' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting and copying text from one file to another

Helooo, So I have a .fasta file (a text file with sequence data) which looks like this, with just over 3 million lines of data. >TCONS_00000001 gene=XLOC_000001 AATTGTGGTGAAATGACTTCTGTTAACGGAGACATCGATGATTGTTGTTACTATTTGTTCTCAGGATTCA... (8 Replies)
Discussion started by: 4galaxy7
8 Replies

2. Shell Programming and Scripting

Copying files with a specific pattern

Hi All I am trying to copy files from one location to another and given below are some sample ones: aaa_bbb_ccc_ddd_cost_code_20140330.gz aaa_bbb_ccc_ddd_revenue_zone_20140329.gz aaa_bbb_ccc_ddd_benefit_extract_20140330.csv.gz aaa_bbb_ccc_ddd_profit_zone_20150509.csv.gz... (17 Replies)
Discussion started by: swasid
17 Replies

3. Shell Programming and Scripting

Copying files based on a pattern

Hi All, I need to find and list the last 5 days files in that exact name with "MIM" and copy to another directory. please help me in this there is around 30000 files Thanks Murali (7 Replies)
Discussion started by: 969murali@gmail
7 Replies

4. UNIX for Dummies Questions & Answers

Copying text from Windows to AIX - missing text?

Hi All, I'm hoping this is an easy question, but I'm having a weird problem trying to simply copy and paste text from MS Windows (XP) Notepad and then pasting into vi or vim in AIX. When I type "oslevel" I get "5.3.0.0". The problem is that once the text is pasted, there are sections of text... (2 Replies)
Discussion started by: PlainInverted
2 Replies

5. Shell Programming and Scripting

Need help with searching and copying in a text file

Hi, I need help searching through a large text file. I need to find a certain string within the text, and copy each line until another string appears. The file looks like this: >scf15164843 ATTAAAGGNNNGGAATTTCCCCAA ATTACCGGCTTTAAANNNTTACCC >scf15154847 CCGGGNNNTTTAAACCCGNGNGCC... (2 Replies)
Discussion started by: repiv
2 Replies

6. UNIX for Advanced & Expert Users

Vi copying text

Is there a trick for copying from something like a powerpoint into vi? Every time I try to copy text from something like a powerpoint to vi my spacing gets messed up. I think it has something to do with my .vimrc file. When I renamed it was able to copy it in just fine so can someone please... (2 Replies)
Discussion started by: cokedude
2 Replies

7. Shell Programming and Scripting

copying columns with headers' specific pattern

Hi friends, I have data in tab separated file with headers like this : *sml1 *sml3 *smln7 smfk9 smllf56... Which shell command I should use if i want to extract entire columns that have header names beginning with "*" ? i want to copy these columns into another file. Thanks, (14 Replies)
Discussion started by: jacks
14 Replies

8. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

9. UNIX for Dummies Questions & Answers

Copying Text between two unique text patterns

Dear Colleagues: I have .rtf files of a collection of newspaper articles. Each newspaper article starts with a variation of the phrase "Document * of 20" and is separated from the next article with the character string "===================" I would like to be able to take the text composing... (3 Replies)
Discussion started by: spindoctor
3 Replies

10. UNIX for Dummies Questions & Answers

copying a pattern of files in one directory into other with new pattern names...

Hi, I have to copy a set of files abc* in /path/ to /path1/ as abc*_bkp. The list of files appear as follows in /path/: abc1 xyszd abc2 re2345 abcx .. . abcxyz I have to copy them (abc* files only) into /path1/ as: abc1_bkp abc2_bkp abcx_bkp .. . (6 Replies)
Discussion started by: new_learner
6 Replies
Login or Register to Ask a Question