Problem in extracting vector data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in extracting vector data
# 1  
Old 03-18-2008
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  
Old 03-18-2008
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 04:23 AM.. Reason: I forgot to add a plus on all lines but the first, but maybe that can be left as an exercise ...
era
# 3  
Old 03-18-2008
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in extracting data using cut/awk command

Hi Everyone, I have a very simple problem and i am stuck in that from last 8 days. I tried many attempts, googled my query but all in vain. I have a text file named "test.txt" In that suppose i have contents like: Java: 1 Object oriented programming language 2 Concepts of Abstraction... (5 Replies)
Discussion started by: Abhijeet Anand
5 Replies

2. Shell Programming and Scripting

Help with extracting data within parentheses

This is my input file: a|b|c(ef)|g|h(km)|p My output file should look like: a|b|ef|g|km|p That is, pipe is the delimiter. The data within pipe must be displayed as it is but if it encounters any data within parentheses, then only the data within parentheses has to be displayed ( the data... (2 Replies)
Discussion started by: ksatish89
2 Replies

3. Programming

Polymorphism delete vector problem

Hi all Really need some help here, i have a vector of pointer "vector<*e.g>store" i need to delete one of the chosen container and it seem like the normal way of deleting a vector cannot work! P.S new to polymorphism Thank Here is a cut out of my codes for(unsigned... (1 Reply)
Discussion started by: GQiang
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

5. Shell Programming and Scripting

extracting data

I have a txt file of the following format >ab_ qwerty >rt_ hfjkil >Ty2 hglashglkasghkf; >P2 aklhfklflkkgfgkfl >ui_ vnllkdskkkffkfkkf >we32 vksksjksj;lslsf'sk's's .... ..... I want to split this big file based on the header (>) (5 Replies)
Discussion started by: Lucky Ali
5 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. UNIX for Dummies Questions & Answers

Help with extracting data and plotting

I have attached a txt file, what I would like to be able to do is: 1. Extract Data from Columns labeled E/N and Ko into a new file 2. Then in the new file I would like to be able to plot E/N on the X axis and Ko on the y axis. 3. Lastly I would like to be able to extract multiple data sets and... (6 Replies)
Discussion started by: gingburg
6 Replies

8. UNIX for Dummies Questions & Answers

Extracting Data Using SED

Given the following text in a file named extract.txt: listenPort:=25 smtpDestination:=2 enableSSL:= I am trying to extract only the value 2 following smtpDestination:= Someone had suggested I use: sed -e "s/^smtpDestination:=\(.*\)$/\1/" extract.txt but this returns: listenPort:=25 2 ... (2 Replies)
Discussion started by: cleanden
2 Replies

9. Shell Programming and Scripting

extracting integer from data

Hi people, I've encountered a problem. I have a data file like: asd:$123:2 zxc:$456:4 But when I want to extract "$123" and get the number with this command: echo $123 | cut -c 1-10 Im returned with 23 instead of 123. Please help me out, thanks. (4 Replies)
Discussion started by: grotesque
4 Replies

10. UNIX for Advanced & Expert Users

For loop problem extracting data

I have a problem with my loops. I have a file called users.dat, it has all the users in it. Then I extracted a list of users sending out number of mails with date from Netscape logs. The extracted list (mailuse.dat) has 3 fields: username, number of mails, date. (One user can show up several... (2 Replies)
Discussion started by: nitin
2 Replies
Login or Register to Ask a Question