The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2008
ahjiefreak ahjiefreak is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 132
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.
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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
In the famous words of Dennis M. Ritchie, You Are Not Supposed to Understand This.

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 ...
  #3 (permalink)  
Old 03-18-2008
yunccll yunccll is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 23
assume that there is only a single line in fileB!
using awk :
Code:
awk 'NR == FNR {var=$0}
       NR != FNR { 
         if(FNR > 1)    $3 = "+"$3;
         print $3 "*" var
       }'  FS="(+)|(-)"  fileB fileA
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0