![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| extracting data from files.. | anchal_khare | Shell Programming and Scripting | 1 | 04-03-2008 06:56 AM |
| extracting integer from data | grotesque | Shell Programming and Scripting | 4 | 01-18-2008 08:18 AM |
| Extracting Data From Sendmail | calex | Shell Programming and Scripting | 3 | 01-15-2007 08:43 AM |
| Extracting certain data from a sentence | dbrundrett | Shell Programming and Scripting | 7 | 12-17-2003 11:22 AM |
| For loop problem extracting data | nitin | UNIX for Advanced & Expert Users | 2 | 11-27-2001 05:20 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Problem in extracting vector data
Hi,
Currently I have two files; A and B. File A has below data:- -3 + <1 2 3 4 5 6 7 8 1 2 > - 1] -2 + <8 8 3 4 0 3 7 9 1 3 > - 1] -1 + <3 7 3 4 8 2 7 2 1 2 > - 1] -3 + <2 2 3 4 3 1 7 8 8 2 > - 1] and File B has below data:- <9 1 1 4 2 6 3 8 8 9 > From these two files, I try to do a cross product vector for these two files. <1 2 3 4 5 6 7 8 1 2 >*<9 1 1 4 2 6 3 8 8 9 > +<8 8 3 4 0 3 7 9 1 3 > *<9 1 1 4 2 6 3 8 8 9 > +<3 7 3 4 8 2 7 2 1 2 > *<9 1 1 4 2 6 3 8 8 9 > +<2 2 3 4 3 1 7 8 8 2 > *<9 1 1 4 2 6 3 8 8 9 > Could anyone show me how I could extract the elements from these two files such as above? As of now I could cat the file A but do not know how to extract elements from < on wards. And i do not know how I could perform division with elements form another file, file B. Please help. Thanks alot. |
|
||||
|
Please add some more hints. Is file B always a single line? Do you want to do this in the Enterprise Silver Platinum Mojo Beans way or just a one-off job?
Code:
sed -e 's/.*/s%^.*\\(<[^<>]*>\\).*%\\1 \* &%/' fileB | sed -f - fileA Actually, as a brief overview, we are taking the contents of fileB (presumably a single line) and wrapping it inside some sed commands, which are then passed as a script to sed to run on fileA. Conveniently, the first sed writes a script for the second containing the contents of fileB and a bit of sed trickery. It's not even tricky at all, once you wrap your head around it (and decode the escapes needed to prevent the literal parts in the first script from being interpreted by the first sed). Last edited by era; 03-18-2008 at 03:23 AM.. Reason: I forgot to add a plus on all lines but the first, but maybe that can be left as an exercise ... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|