Need to add prefix using sed or awk from cat the file

I need the use sed or AWK using cat the file

Node1
TDEV RW 1035788
TDEV RW 1035788
Server1
TDEV RW 69053
Server2
TDEV RW 69053
TDEV RW 103579
Server3
TDEV RW 69053
server4
RDF1+TDEV RW 69053
RDF1+TDEV RW 517894
RDF1+TDEV RW 621473
server6
TDEV RW 34526
TDEV RW 34526
RDF1+TDEV RW 34526
RDF1+TDEV RW 34526
TDEV RW 34526

I need the output like this

Node1,TDEV RW 1035788
Node1,TDEV RW 1035788
Server1,TDEV RW 69053
Server2,TDEV RW 69053
Server2,TDEV RW 103579
Server3,TDEV RW 69053
server4,RDF1+TDEV RW 69053
server4,RDF1+TDEV RW 517894
server4,RDF1+TDEV RW 621473
server6,TDEV RW 34526
server6,TDEV RW 34526
server6,RDF1+TDEV RW 34526
server6,RDF1+TDEV RW 34526
server6,TDEV RW 34526

This problem has been solved umpteen times in these forums. Did you bother to do a search as recommended in the rules?

However, try

awk 'NF == 1 {PRFX = $1; next} {print PRFX "," $0}' file
Node1,TDEV RW 1035788
Node1,TDEV RW 1035788
Server1,TDEV RW 69053
Server2,TDEV RW 69053
Server2,TDEV RW 103579
Server3,TDEV RW 69053
server4,RDF1+TDEV RW 69053
server4,RDF1+TDEV RW 517894
server4,RDF1+TDEV RW 621473
server6,TDEV RW 34526
server6,TDEV RW 34526
server6,RDF1+TDEV RW 34526
server6,RDF1+TDEV RW 34526
server6,TDEV RW 34526

Thanks i am search in google not able to find the right code. It work great if i have any doubt on procession i will come back

---------- Post updated at 08:31 AM ---------- Previous update was at 07:17 AM ----------

Hi RudiC

Could you please help to provide a solution using awk or diff command. I need to add one more prefix by compare a file input. Since the file very large it will contain more then 10k devs. I can't compare in loop. Instead in want to use diff or some other compare command

Real file

Node1,dev2,nofast,TDEV RW 1035788
Node1,dev10,nofast,TDEV RW 1035788
Server1,dev14,nofast,TDEV RW 69053
Server2,dev4,nofast,TDEV RW 69053
Server2,dev1,nofast,TDEV RW 103579
Server3,dev7,nofast,TDEV RW 69053
server4,dev11    RDF1+TDEV RW 69053
server4,dev9    RDF1+TDEV RW 517894
server4,dev3    RDF1+TDEV RW 621473
server6,dev5,nofast,TDEV RW 34526
server6,dev8,nofast,TDEV RW 34526
server6,dev13    RDF1+TDEV RW 34526
server6,dev12    RDF1+TDEV RW 34526
server6,dev6,nofast,TDEV RW 34526
The input file will have 20k devs like that 

dev14
dev15
dev16
dev17
dev18
dev19
dev20
dev21
dev1
dev23
dev24
dev25

I need output will be like this "nofast,T1"

Server1,dev14,nofast,T1,TDEV RW 69053
Server2,dev4,nofast,TDEV RW 69053
Server2,dev1,nofast,T1,TDEV RW 103579
Server3,dev7,nofast,TDEV RW 69053
server4,dev11    RDF1+TDEV RW 69053
server4,dev9    RDF1+TDEV RW 517894
server4,dev3    RDF1+TDEV RW 621473
server6,dev5,nofast,TDEV RW 34526
server6,dev8,nofast,TDEV RW 34526
server6,dev13    RDF1+TDEV RW 34526
server6,dev12    RDF1+TDEV RW 34526
server6,dev6,nofast,TDEV RW 34526

Not clear. How do you connect Node1 to dev2 and dev10 , and server1 to dev14 ? Where does nofast and / or T1 come from? Why and when do they show up together and when not?
Please be VERY specific in your answer!

That was final processed output after this output i need to compare with the file which will have only devs info. I need check the file and compare only with the device mention in "nofast". I dont want to use "forloop" since number of device will be more it will take time. Instead i want to compare only the awk output of nofast device and update the prefix

If the device found in the input file update the field with nofast_T1 if not found update with nofast_nofound

---------- Post updated at 09:40 AM ---------- Previous update was at 08:48 AM ----------

Source file -file1

Server1,dev14,nofast,TDEV RW 69053
Server2,dev4,nofast,TDEV RW 69053
Server2,dev1,nofast,TDEV RW 103579
Server3,dev7,nofast,TDEV RW 69053

Input file -file2

dev14
dev15
dev16
dev17
dev18
dev19
dev20
dev21
dev1
dev23
dev24
dev25

I need output

Server1,dev14,nofast_found,TDEV RW 69053
Server2,dev4,nofast_not_found,TDEV RW 69053
Server2,dev1,nofast_found,TDEV RW 103579
Server3,dev7,nofast_not_found,TDEV RW 69053

I need to use awk lookup on this. But i dont how to filter source file coloum2 and Vlookup with input file and check the record is found on that file

awk 'NR==FNR {m[$1]=$1; next} {$1=m[$1]; print}' file1 file2
1 Like

Please reread your statement of what needs to be done marked in red above. Then note that some lines in your output have nofast_found which is not mentioned as an output that should be produced. And note that no output contains the string nofast_T1 which you said should be produced for any line where the 2nd field in file1 is found as a 1st field value in file2 . And note that no output contains the string nofast_nofound (although some do contain nofast_not_found ).

If you can't give us a description of the work that needs to be done by a script that matches the output you say you want, there isn't much chance of us being able to help you write a script that does what you want it to do.

Is there still some other intermediate step that you haven't told us about that changes nofast_T1 to nofast_found and changes nofast_nofound to nofast_not_found possibly with some other requirements you haven't mentioned?

Hi DOn,

Pls use my input as new program i need to compare two file and provide new output

First file will has the information has mention (file1)
Second file will be (file2)

I need to Vlookup each line from file1 "column 2" to each line of "File2"

Update the "File1" for all the "dev" found from "file2" has

dev14,Found
dev4,not_found

I cant use forloop since i have to check more then 10k devs from file1 with file2. Instead is there any solution what we do in excel Vlookup

OK, still not clear to me. But with the second part of post #5, let's try this:

awk '
  NR==FNR {
    A[$1]
    next
  }
  { 
    if($2 in A)
      $3=$3 "_found"
    else
      $3=$3 "_not_found"
    print
  }
' file2 FS=, OFS=, file1

Output:

Server1,dev14,nofast_found,TDEV RW 69053
Server2,dev4,nofast_not_found,TDEV RW 69053
Server2,dev1,nofast_found,TDEV RW 103579
Server3,dev7,nofast_not_found,TDEV RW 69053

Sorry the input file has changed. I need to grep first only the device which has "no_fast" and check with file-2 if the devs found update the row with fast_found and other no_fast device to no_fast_no_found.

And i need to output with all the row in same order as inputfile

File-1 (Updated new input)

frame1,no_fast,Server1, 9858 N/A TDEV RW 34526 
frame1,no_fast,Server1, 9859 N/A TDEV RW 34526 
frame1,no_fast,Server1, 985A N/A TDEV RW 34526 
frame1,no_fast,Server1, 985C N/A TDEV RW 103579 
frame1,no_fast,server2, 3F9C N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3F9D N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3F9E N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3F9F N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA0 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA1 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA2 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA3 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA4 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA5 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 3FA6 N/A RDF1+TDEV RW 34526 
frame1,no_fast,server2, 6204 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA7 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA8 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA9 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FAA N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FAB N/A RDF1+TDEV RW 34526 

file-2

3F9E
9858

Output Required

frame1,fast_found,Server1, 9858 N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 9859 N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 985A N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 985C N/A TDEV RW 103579 
frame1,no_fast_not_found,server2, 3F9C N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3F9D N/A RDF1+TDEV RW 34526 
frame1,fast_found,server2, 3F9E N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3F9F N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA0 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA1 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA2 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA3 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA4 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA5 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA6 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 6204 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA7 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA8 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA9 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FAA N/A RDF1+TDEV RW 34526
frame1,VMAX_CLASS2,server3, 3FAB N/A RDF1+TDEV RW 34526

Hello ranjancom2000,

Please use code tags as per forum rules for sample Input_file and expected output. Could you please let me know if this helps you.

awk '
FNR==NR{
  a[$0];
  next
}
{
num=split($1, array,",")
}
{
array[2]=$2 in a?"fast_found":"no_fast_no_found";
for(i=1;i<=num;i++){
  val=val?val","array:array
};
$1=val
}
{
print;
val=""
}' File-2 File-1

Output will be as follows.

frame1,fast_found,Server1, 9858 N/A TDEV RW 34526
frame1,no_fast_no_found,Server1, 9859 N/A TDEV RW 34526
frame1,no_fast_no_found,Server1, 985A N/A TDEV RW 34526
frame1,no_fast_no_found,Server1, 985C N/A TDEV RW 103579
frame1,no_fast_no_found,server2, 3F9C N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3F9D N/A RDF1+TDEV RW 34526
frame1,fast_found,server2, 3F9E N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3F9F N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA0 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA1 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA2 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA3 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA4 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA5 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 3FA6 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server2, 6204 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server3, 3FA7 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server3, 3FA8 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server3, 3FA9 N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server3, 3FAA N/A RDF1+TDEV RW 34526
frame1,no_fast_no_found,server3, 3FAB N/A RDF1+TDEV RW 34526
 

Thanks,
R. Singh

1 Like

Hi RavinderSingh13,

Script is working but it print in the screen i need redirect to file. Where i need to put the redirect to file output

This is the third time you change your request. How about getting your act together in the first place, and post a decent, meaningful, and carefully phrased specification that you don't need to correct several times?

For your last request, try

awk -F, '
FNR==NR         {T[$0]
                 next
                }

/no_fast/       {num = split ($NF, ARR, " ")
                 if (ARR[1] in T)       sub (/no_/, "", $2)
                   else                 sub (/fast/, "&_not", $2)
                 $2 = $2 "_found"
                }
1
' OFS=","  file2 file1
frame1,fast_found,Server1, 9858 N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 9859 N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 985A N/A TDEV RW 34526 
frame1,no_fast_not_found,Server1, 985C N/A TDEV RW 103579 
frame1,no_fast_not_found,server2, 3F9C N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3F9D N/A RDF1+TDEV RW 34526 
frame1,fast_found,server2, 3F9E N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3F9F N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA0 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA1 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA2 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA3 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA4 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA5 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 3FA6 N/A RDF1+TDEV RW 34526 
frame1,no_fast_not_found,server2, 6204 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA7 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA8 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FA9 N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FAA N/A RDF1+TDEV RW 34526 
frame1,VMAX_CLASS2,server3, 3FAB N/A RDF1+TDEV RW 34526

Hello ranjancom2000,

You need to put > Output_file at the end of above code, let me know if any queries on same.

Thanks,
R. Singh

Hi RudiC,

Sorry the output file keep changing every time. So i need to request but i can get the RavinderSingh13 script working. Now i need the print out to file not on screen.

---------- Post updated at 11:51 AM ---------- Previous update was at 08:14 AM ----------

I am using code tag for this. I think this is correct

Hi RavinderSingh13,

Some strange i ran the script by using code. But i this output it was renaming the "Tier1" also. Could you please chk what is causing this issue

Input file

Frame1,Tier1,Server1, 120B N/A TDEV RW 34526 
Frame1,Tier1,Server1, 120C N/A TDEV RW 34526 
Frame1,Tier1,Server1, 120D N/A TDEV RW 34526 
Frame1,Tier1,Server1, 120E N/A TDEV RW 34526 
Frame1,Tier1,Server1, 120F N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1210 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1211 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1212 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1213 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1214 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1215 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1216 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1217 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1218 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 1219 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121A N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121B N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121C N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121D N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121E N/A TDEV RW 34526 
Frame1,Tier1,Server1, 121F N/A TDEV RW 34526 
Frame1,no_fast,Server2, 2955 N/A RDF1+TDEV RW 69053 
Frame1,no_fast,Server2, 2995 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 2999 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 299D N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29A1 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29A5 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29A9 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29AD N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29B1 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 29B5 N/A RDF1+TDEV RW 138105 
Frame1,no_fast,Server2, 2A73 N/A RDF1+TDEV RW 34526

output file

Frame1,no_fast_Not_Bounded,Server1, 120B N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 120C N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 120D N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 120E N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 120F N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1210 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1211 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1212 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1213 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1214 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1215 N/A TDEV RW 34526
Frame1,no_fast_Not_Bounded,Server1, 1217 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1218 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 1219 N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121A N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121B N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121C N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121D N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121E N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server1, 121F N/A TDEV RW 34526 
Frame1,no_fast_Not_Bounded,Server2, 2955 N/A RDF1+TDEV RW 69053 
Frame1,no_fast_Not_Bounded,Server2, 2995 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 2999 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 299D N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29A1 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29A5 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29A9 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29AD N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29B1 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 29B5 N/A RDF1+TDEV RW 138105 
Frame1,no_fast_Not_Bounded,Server2, 2A73 N/A RDF1+TDEV RW 3452

Hello ranjancom2000,

Since you haven't mentioned that we have another data too apart from no_fast , so I haven't put any check/condition on same, could you please check following and let me know if this helps you.

awk '
FNR==NR{
  a[$0];
  next
}
{
num=split($1, array,",")
}
{
if(array[2] ~ "no_fast"){
  array[2]=$2 in a?"fast_found":"no_fast_no_found";
}
for(i=1;i<=num;i++){
  val=val?val","array:array
};
$1=val
}
{
print;
val=""
}' File-2 File-1

With your NEWLY provided Input_file, following will the output on same.

Frame1,Tier1,Server1, 120B N/A TDEV RW 34526
Frame1,Tier1,Server1, 120C N/A TDEV RW 34526
Frame1,Tier1,Server1, 120D N/A TDEV RW 34526
Frame1,Tier1,Server1, 120E N/A TDEV RW 34526
Frame1,Tier1,Server1, 120F N/A TDEV RW 34526
Frame1,Tier1,Server1, 1210 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1211 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1212 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1213 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1214 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1215 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1216 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1217 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1218 N/A TDEV RW 34526
Frame1,Tier1,Server1, 1219 N/A TDEV RW 34526
Frame1,Tier1,Server1, 121A N/A TDEV RW 34526
Frame1,Tier1,Server1, 121B N/A TDEV RW 34526
Frame1,Tier1,Server1, 121C N/A TDEV RW 34526
Frame1,Tier1,Server1, 121D N/A TDEV RW 34526
Frame1,Tier1,Server1, 121E N/A TDEV RW 34526
Frame1,Tier1,Server1, 121F N/A TDEV RW 34526
Frame1,no_fast_no_found,Server2, 2955 N/A RDF1+TDEV RW 69053
Frame1,no_fast_no_found,Server2, 2995 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 2999 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 299D N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29A1 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29A5 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29A9 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29AD N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29B1 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 29B5 N/A RDF1+TDEV RW 138105
Frame1,no_fast_no_found,Server2, 2A73 N/A RDF1+TDEV RW 34526
 

Kindly do let me know if you have any queries on same.

Thanks,
R. Singh

1 Like

hi RavinderSingh13,

It is working now now. This is new script I need to same format but i need to check two conduction from file2 and update in file1.

check the server name from file1 if the server found on file2. I need to take Tier value from file2 and update the record of file1 for that server for all device.

file1

Frame1,check_fast,Server1, 0EAD N/A TDEV RW 69053 
Frame1,check_fast,Server1, 0F36 N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F37 N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F38 N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F39 N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F3A N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F3B N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F3C N/A TDEV RW 34526 
Frame1,check_fast,Server1, 0F3D N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F2 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F3 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F4 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F5 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F6 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F7 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F8 N/A TDEV RW 34526 
Frame1,check_fast,server2, 44F9 N/A TDEV RW 34526

file2

server1 Tier1
test Tier2
test_T1 Tier1

Need output

Frame1,Tier1,Server1, 0EAD N/A TDEV RW 69053 
Frame1,Tier1,Server1, 0F36 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F37 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F38 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F39 N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F3A N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F3B N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F3C N/A TDEV RW 34526 
Frame1,Tier1,Server1, 0F3D N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F2 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F3 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F4 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F5 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F6 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F7 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F8 N/A TDEV RW 34526 
Frame1,notin_fast,server2, 44F9 N/A TDEV RW 34526 

Hello ranjancom2000,

Could you please try following and let me know if this helps you.

awk 'FNR==NR{a[$1]=$2;next} {$2=tolower($3) in a?a[tolower($3)]:"notin_fast"} 1' OFS="," FS=" "  Input_file2  FS=","   Input_file1

Output will be as follows.

Frame1,Tier1,Server1, 0EAD N/A TDEV RW 69053
Frame1,Tier1,Server1, 0F36 N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F37 N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F38 N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F39 N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F3A N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F3B N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F3C N/A TDEV RW 34526
Frame1,Tier1,Server1, 0F3D N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F2 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F3 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F4 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F5 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F6 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F7 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F8 N/A TDEV RW 34526
Frame1,notin_fast,server2, 44F9 N/A TDEV RW 34526
 

Thanks,
R. Singh

hi RavinderSingh13,

Great the script is working. But it ignore the host which is in CAPS. How i make the script to check ignore CAPS

Hello ranjancom2000,

I thought you don't care about the server names(you need not to keep case sensitive), if you need server keywords to be case sensitive then you could change from tolower($3) to normal $3 . But again since I haven't seen any Input_file from you so this is a general statement, if your requirement differs then you have to show us the sample Input_file along with sample output too in code tags.

Thanks,
R. Singh

1 Like

Yes now it was working great