awk and grep using two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and grep using two files
# 1  
Old 02-05-2016
awk and grep using two files

I have two file one will have WWN and port details and another file will have allies name. I need to check what allies name was given to each wwn and create a consolidate report which will both port details, allies name.


file one switchshow



PHP Code:
 133    1   21   188500   id    N4         Online      FC  F-Port  10:00:00:00:c9:67:51:4b
 134    1   22   188600   id    N4         Online      FC  F
-Port  10:00:00:90:fa:0c:aa:e7 



File two alishow


PHP Code:
cat alishow |grep -B1 10:00:00:00:c9:67:51:4b |grep alias
alias
hostname_01 
I need output like this


PHP Code:
133    1   21   188500   id    N4         Online      FC  F-Port  10:00:00:00:c9:67:51:4baliashostname_01 

# 2  
Old 02-05-2016
Hi, try:
Code:
awk 'FNR == NR && $10 ~ /([0-9a-f]+:){7}[0-9a-f]+/ {A[$10]=P};FNR == NR {P=$0;next};$10 ~ /([0-9a-f]+:){7}[0-9a-f]+/ {$10=$10 ";" A[$10]}1' alishow switchshow

Regards.
# 3  
Old 02-05-2016
Its not that easy to guess your second input file's structure; your cat | grep | grep doesn't really help. Nevertheless, try also
Code:
awk 'FNR == NR {match ($0, /[A-Fa-f0-9:]+/); A[substr ($0, RSTART, RLENGTH)] = LAST; LAST = $0; next} $NF in A {print $0 ";", A[$NF]}' file2 file1
 133    1   21   188500   id    N4         Online      FC  F-Port  10:00:00:00:c9:67:51:4b; alias: hostname_01

# 4  
Old 02-05-2016
Hi RudiC I am getting output like this if i use your command

PHP Code:
 128    1   16   188000   id    N8         Online      FC  F-Port  50:00:09:74:08:1b:b9:c8 ;            50:00:09:74:08:1a:91:c8
 129    1   17   188100   id    N8         Online      FC  F
-Port  50:00:09:74:08:1b:b9:cc ;            50:00:09:74:08:1a:91:cc 
I need one line before it will have the alias name for that wwn. Is there any way i can use for loop.

First awk only the WWN from file switchshow and save in one file 111
second use the for loop to check one by one WWN using
PHP Code:
|grep -B1 "WWN" |grep alias 
and save the out as 222

and add the 222 out as priffx to the
switchshow file

Last edited by ranjancom2000; 02-05-2016 at 08:49 AM..
# 5  
Old 02-05-2016
Please post small but representative samples of your input files, using code tags NOT PHP tags.

---------- Post updated at 15:19 ---------- Previous update was at 15:18 ----------

AND an output sample.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

2. Homework & Coursework Questions

Help with exit, grep, temporary files, awk

1. The problem statement, all variables and given/known data: I do not understand how/why the following code is used. Please do not simply refer me to the man pages since I have already reviewed them extensively. Thank you. exit 2 , exit 3, exit 0 I understand the basics of why the exit... (5 Replies)
Discussion started by: BartleDoo
5 Replies

3. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 12.4 1.72849432773174e+01 -7.74784188610632e+01 12.5 9.59432114416327e-01 -7.87018212757537e+01 15.6 5.20139995965960e-01 -5.61612429666624e+01 29.3 3.76696387248366e+00 -7.42896194101892e+01 32.1 1.86899877018077e+01 -7.56508762501408e+01 35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies

4. Shell Programming and Scripting

piping from grep to awk without intermediate files

I am trying to extract the file names alone, for example "TVLI_STATS_NRT_XLSTWS03_20120215_132629.csv", from below output which was given by the grep. sam:/data/log: grep "C10_Subscribe.000|subscribe|newfile|" PDEWG511_TVLI_JOB_STATS.ksh.201202* Output: ... (6 Replies)
Discussion started by: siteregsam
6 Replies

5. Shell Programming and Scripting

Compare intervals (columns) from two files (awk, grep, Perl?)

Hi dear users, I need to compare numeric columns in two files. These files have the following structure. K.txt (4 columns) A001 chr21 9805831 9846011 A002 chr21 9806202 9846263 A003 chr21 9887188 9988593 A003 chr21 9887188 ... (2 Replies)
Discussion started by: jcvivar
2 Replies

6. Shell Programming and Scripting

Cat 114 files using grep or awk to pull muliple fields

Files xxxxxxx.txt ------------------------------------------------------------------------------------------------------------------------------------ Req.By: xxxxxxx WABUSH MINES - xxxxxx MINE (1001) Page: 1 Run on: 12/14/09... (4 Replies)
Discussion started by: sctxms
4 Replies

7. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

8. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

9. Shell Programming and Scripting

Reading files using grep/sed/awk

After pouring over my LTKS and Unix in a nutshell, I'm stuck! I have a large (BMC Report File) that has breaks on DM (district managers). After a report header, there is a DM header like: DM: DBP AARON ROBERTS At the end of each DM break, there is: ** END OF REPORT ** ... (6 Replies)
Discussion started by: Jodyman
6 Replies

10. UNIX for Dummies Questions & Answers

Constantly updating log files (tail -f? grep? awk?)

I have a log file which is continuously added to, called log.file. I'd like to monitor this file, and when certain lines are found, update some totals in another file. I've played around with tail -f, grep, and awk, but can't seem to hit the right note, so to speak. The lines I'm... (0 Replies)
Discussion started by: nortonloaf
0 Replies
Login or Register to Ask a Question