hey i was messing around a bit ... made me wonder...
If the error_correction.txt file had 3 columns,:
VenoM,Venom,Antivenom
nos,NOS,N2O
..
.
.
.
Now Suppose i have an if statement and depending on it i have to choose a value from column 2 or column 3, to replace the value in the main datafile.
How do i do this?
i have around 4 conditions to check!
is it possible to redirect it to a subroutine? Or is it possible to use a something like a switch case?
Im doing something like this:
{
x=substr($1,2,5);
}
if ( x == "JB007" )
{
#Assign the value from the 3rd column of the error_correction file
}
else
{
#Assign the value from the 2nd column of the error_correction file
}
create a function that would return a binary value - check the returned value as in above.
Or better yet, just create a function that will return either $2 or $3, return this value - you'll do the array assignment of the return value.
hope im not bugging you too much......
but hey another twist to this
what if i had: VenoM,Venom,am1
Venom,VENOM,ax2
nos,NOS,ba1
nos,N2O,gd2
nos,n2o,as3
..
.
.
.
In this case, how do i pick out the value in the second column after matching 2 variables ie the 1st and the 3rd column to my main data file [assuming that the 3rd column is present in the 3rd field of the data file]
Sorry, don't follow you.
Could you give a better description.
Also, start using code tags when posting code/data samples - you'll improve the chances of your questions being looked at/answered.
My data file looks like this:
vgr,bugatti veron,,3.5,Venom,6,.......,....
vgr,lamborgini,,3.5,nos,6,.......,....
abc,bugatti veron,,3.5,Venom,6,.......,.......
.
.
.
.
What happens when there are multiple occurrences of the value to be replaced in my error correction file
Like nos appears twice but all we are doing is:
This only matches the first occurrence.......
how do we make this a loop?
Hi,
I have a file like below
PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Hi Friends,
I have looked around the forums and over online but couldn't figure out how to deal with this problem
input.txt
gene1,axis1/0/1,axis2/0/1
gene1,axis1/1/2,axis2/1/2
gene1,axis1/2/3,axis2/2/3
gene2,axis1/3/4,axis2/3/4
Match on first column and if first column is... (1 Reply)
Need an awk script to calculate the percentage of value field and replace
I have a input file called file.txt with the following content:
john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2
andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1
in fourth filed of input file, calulate percentage of each... (1 Reply)
I have some problem with this.
Need to change field #3 to 5 if field #1 = A and filed #2 =B
DataA C 6 T
C B 4 R
A B 3 T
D E 5 4
I would like to do two things if statement is true, but can not get it to work.
Here it prints column #3 if statement is true, and this works
awk '{if... (3 Replies)
Hi
I would like to apply this gawk command:
gawk '{$0=gensub(/\y+\y/,"","g"); print}' file
not to the whole $0 but just to the part of $0 that is between:
(a number)"> and </mrk>
Is it possible?
thanks for your help. (4 Replies)
Hello everybody:
I want to replace any field $2 of any file line (f.i. test.txt) matching $1 with a shell variable.
$ cat test.txt
F 0
B A
H -12.33
Now I'm going to ask the value of variable B:
$ SEARCHVAR=B
$ OLDVAL=$(awk -v SEARCHVAR="$SEARCHVAR"... (4 Replies)
I need to replace specific field (x) in a table with new value (y):
Input:
1 2 3 4
5 x 6 7
8 9 0 0
Output:
1 2 3 4
5 y 6 7
8 9 0 0
I have no idea how to do this. (10 Replies)
I am writing a c++ program that has many calls of pow(input,2). I now realize that this is slowing down the program and these all should be input * input for greater speed.
There should be a simple way of doing this replacement throughout my file with awk, but I am not very familiar with awk.... (2 Replies)
Hi
I am using awk to replace the 4th feild of the input line. My code is below:
REP_LINE=$(echo $Line | awk -v var=$REPL_DT '{$4=var; print}')
It does replaces but all words/phrases after the 4th feild are erased. Is there a way to modify the 4th feild of the input line and to have all... (7 Replies)
I got a sample file like this.
$ cat test
12|13|100|s
12|13|100|s
100|13|100|s
12|13|100|s
I want to replace all 100 by 2000 only in 3rd field using "awk"
This is replacing all 100's :-(
$ awk -F "|" '{gsub( /100/,"2000");print}' test
12|13|2000|s
12|13|2000|s
2000|13|2000|s... (5 Replies)