![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| text manipulation | injeti | Shell Programming and Scripting | 11 | 06-05-2008 10:42 AM |
| Text file manipulation | Ezy | UNIX for Dummies Questions & Answers | 4 | 02-25-2008 01:15 PM |
| Text Manipulation. | Icepick | Shell Programming and Scripting | 4 | 02-25-2008 04:18 AM |
| Text file manipulation | svannala | UNIX for Dummies Questions & Answers | 5 | 01-20-2006 07:01 PM |
| shell script : text manipulation (easy quesiton) | champion | Shell Programming and Scripting | 3 | 07-01-2002 03:10 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
I am tryin to figure out how to extract interested text from file
example.txt blah blah blah a: child1 blah a: child2 blah b: parent1 blah blah blah .... blah a: child21 blah a: child22 blah a: child23 blah b: parent2 this kinda text repeats .. number of children is not fixed they vary randomly.. the goal is to end up with a file whihc has all the children names under the related parent name. |
|
||||
|
Expected output:
In a text file: Parent1 child1 child2 parent2 child21 child22 child23 parent3 child31 child32 .... *************************************** In the file 'a' and 'b' are the identifiers for the parent and children. Thanks to you. I thought of doing something like: step 1: Grep for parents and then after I get the list of parents {may be in an array} step 2: I can grep for children with a condition which checks if I hit the first parent from the previously obtained list. When I hit the first parent then save the child list to a text file with the parent name on it. step 3: Again proceed for the next ones by keeping every thing in a for loop and update the text file every time. If this algorithm sounds good then the point I am stuck with is step 2. can you help me out there/ or with any other alternative way. |
|
||||
|
May be a regexpression
May be a regexpression can do it easily.
A command like: grep expression textfile.txt | tee newfile.txt where expresion will say list me all lines which has 'a:' or 'b:' in it and now the newfile.txt will have all my interested lines. with the parent names below their child names {I some how have to get rid of the extra text like blah blah } Can you point me how the regexpression should be like |
|
||||
|
@ haris this is the third time you post the very same question on someone else's post. I have replied to your problem here:
Parsing log files, displaying logs between specific dates |
![]() |
| Bookmarks |
| Tags |
| cut, grep |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|