Sponsored Content
Top Forums Shell Programming and Scripting Using Awk to efficiently substitute values using 3 vectors Post 302394501 by LaTortuga on Thursday 11th of February 2010 03:13:58 PM
Old 02-11-2010
Data Using Awk to efficiently substitute values using 3 vectors

I'm trying to efficiently combine the fields of two vectors (vectors b and c) into a new vector (vector d) as defined by instructions from a 3rd vector (vector a). So vector a has either a 1 or 2 in each field specifying which vector (b or c respectively) should go into that field. Vector a is space separated, while vectors b, c, and d are semicolon separated. I made a bash/awk script which does this, but it takes a while:
Code:
z=0
for y in `echo $a_vect`
do
  z=$(( $z + 1 ))            
  if [ "$y" -eq 1 ]; then 
    temp_var=`echo ${b_vect} | awk -F';' '{print $"'"${z}"'"}'`
    d_vect=`echo -ne "${d_vect};${temp_var}"`
  else
    temp_var=`echo ${c_vect} | awk -F';' '{print $"'"${z}"'"}'`
    d_vect=`echo -ne "${d_vect};${temp_var}"`
  fi
done


Last edited by Scott; 02-11-2010 at 04:29 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitute variable values

Hi, I am trying to redefine the value of a variable based on another variable value. And I want to read in my variables from a enviroment file in the end -- at least I think so. But 1st here's what I want I need to get working: var_1="11 10 9 8 7 6 5 4 3 2 1" var_2=3 var_3=4 So I want... (12 Replies)
Discussion started by: John Rihn
12 Replies

2. Shell Programming and Scripting

Using awk to substitute columns from one file into another

Hi, I am new to this forum and my script skills are very weak. I have this file (file 1) that contains 3 columns (tab delimited): kyle start stop john start stop joe start stop And I want to replace name (column 1) from another file. This other file has two columns, one is the... (4 Replies)
Discussion started by: kylle345
4 Replies

3. Shell Programming and Scripting

AWK Multiple substitute

I want to reformat the following: ID1 ID001 0 0 2 1 GG TC GG CT GG AA AA AG ID2 ID002 0 0 2 2 GG 00 AG CC GG GG TC CC I want to replace only:... (1 Reply)
Discussion started by: genehunter
1 Replies

4. Shell Programming and Scripting

how to substitute filepaths with sed or awk?

I am having the following problem. I am having a lot of files (test_1_01.hea, test_1_02.hea, etc) with the content: project_directory /net/1/d_1/5/ tmp_directory /net/1/d_1/5/ material_directory /net/1/d_1/5/ And I have to substitute the filepaths with new counted ones where the... (3 Replies)
Discussion started by: ergy1983
3 Replies

5. Shell Programming and Scripting

substitute variable for values in perl

hi all, how do i assign values passed in from command line to and sql statement in perl ?? e.g i want to assign :name1 and :Name2 to be whatever is passed into the perl script command line my $sqlStr = "select * from test_table where column1 = upper(nvl(:name1, name1 )) and column2... (1 Reply)
Discussion started by: cesarNZ
1 Replies

6. Shell Programming and Scripting

AWK variable substitute issue

dear, I have below file called folderlist.txt # ParentFolder environment_flag SubFolders triss 1 checksum bookstructure 1 fx 1 checksum_GMDB I have a script which which will create the folders under... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

7. Shell Programming and Scripting

substitute with awk

When the line contains abc, it will goes to the next line and substitue the MM to NN bc 23 33 abc 23 33 ddd MM xx dff MM 33 cat xxx |awk '{if ($0~/abc/){getline;sub(/MM/,"NN")}{print}}', It doesn't show "abc 23 33 bc 23 33 ddd NN xx dff MM 33 bc 23 33 abc 23 33 ddd NN xx... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

8. Shell Programming and Scripting

awk to substitute ip without zero left padding

Hello All, I have this script to awk IP to new file. #awk '/myip|yourip/ {sub(/...\....\....\..../, newip)}1' newip=$IP existing.txt > new.txt When existing.txt has myip=192.168.123.123 and $IP has 192.168.12.12, the awk script is not working. But while I add zero left padding to $IP i.e,... (3 Replies)
Discussion started by: Shaan_Shaan
3 Replies

9. UNIX for Dummies Questions & Answers

Sort and vectors on awk

Well, i have a script and it makes a txt like this : Caps 12 cans 9 cols 10 my print line is something like this for(i in a) print i, a; i have to order the txt from higher to low like: (6 Replies)
Discussion started by: matius_88
6 Replies

10. Shell Programming and Scripting

Substitute from awk results

Hi, The following awk command : asmcmd lsdg | awk '{print $13;}' | grep -i ${SID} return the following output . An Empty line + two lines contain "/" at the end of the line INDEVDATA/ INDEVFRA/ I need to remove the "/" as well as the empty line. Please advise Thanks (3 Replies)
Discussion started by: Yoav
3 Replies
mlib_VectorConjRev_S8C_S8C_Sat(3MLIB)			    mediaLib Library Functions			     mlib_VectorConjRev_S8C_S8C_Sat(3MLIB)

NAME
mlib_VectorConjRev_S8C_S8C_Sat, mlib_VectorConjRev_S16C_S16C_Sat, mlib_VectorConjRev_S32C_S32C_Sat - vector conjugation reversion SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_VectorConjRev_S8C_S8C_Sat(mlib_s8 *z, const mlib_s8 *x, mlib_s32 n); mlib_status mlib_VectorConjRev_S16C_S16C_Sat(mlib_s16 *z, const mlib_s16 *x, mlib_s32 n); mlib_status mlib_VectorConjRev_S32C_S32C_Sat(mlib_s32 *z, const mlib_s32 *x, mlib_s32 n); DESCRIPTION
Each of these functions computes the complex reversion of a complex vector. The source and destination vectors must be in the same data type. The following equation is used: z[2*i] = x[2*(n - 1 - i)] z[2*i + 1] = -x[2*(n - 1 - i) + 1] where i = 0, 1, ..., (n - 1). PARAMETERS
Each of the functions takes the following arguments: z Pointer to the first element of the destination vector. x Pointer to the first element of the source vector. n Number of elements in the vectors. RETURN VALUES
Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) SunOS 5.11 2 Mar 2007 mlib_VectorConjRev_S8C_S8C_Sat(3MLIB)
All times are GMT -4. The time now is 07:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy