Script help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script help
# 8  
Old 03-02-2005
Quote:
Originally Posted by penfold
vg, if i could tap your knowledge one more time...

how would I modify the above script to use the 4 field in gmrd.txt and the 1st field in core_extract.txt?
Code:
awk '
  BEGIN {                                        
     FS = OFS = ";"   
  }

  FNR==NR { arr[$4]=$0; next }
  $1 in arr { print arr[$1] }
  ' gmrd.txt core_extract.txt

# 9  
Old 03-02-2005
Question

using the code above on the following two files:

core.txt:

5069211;00;123
NOASCOMGR;03;143
US36204YA782;00;156
XS0147500028;00;132

gmrd.txt

BAY GR;03;1344;432
235649;03;2563;598
291802;00;2563;598
979217;00;2563;598
235649;03;2563;598
A0ABVB;00;2563;598
235649;03;2563;598

and the following code:

awk '
BEGIN {
FS = OFS = ";"
}

FNR==NR { arr[$2]=$0; next }
$2 in arr { print arr[$1] }
' gmrd.txt core.txt

this results in null output - even though the first file contains a '03'

is this right?
# 10  
Old 03-02-2005
Quote:
Originally Posted by penfold
using the code above on the following two files:

core.txt:

5069211;00;123
NOASCOMGR;03;143
US36204YA782;00;156
XS0147500028;00;132

gmrd.txt

BAY GR;03;1344;432
235649;03;2563;598
291802;00;2563;598
979217;00;2563;598
235649;03;2563;598
A0ABVB;00;2563;598
235649;03;2563;598

and the following code:

awk '
BEGIN {
FS = OFS = ";"
}

FNR==NR { arr[$2]=$0; next }
$2 in arr { print arr[$1] }
' gmrd.txt core.txt

this results in null output - even though the first file contains a '03'

is this right?
Code:
 $2 in arr { print arr[$2] }

# 11  
Old 03-02-2005
Computer

can i award vg a medal for being brainy!

thanks for all your help
# 12  
Old 03-02-2005
CPU & Memory

after having tried this and based on the above two text files the output that is produced is:

A0ABVB;00;2563;598
235649;03;2563;598
A0ABVB;00;2563;598
A0ABVB;00;2563;598

- what am i doing wrong? As what is should produce is the records in gmrd.txt that have the same second field as in core.txt
# 13  
Old 03-02-2005
Quote:
Originally Posted by penfold
after having tried this and based on the above two text files the output that is produced is:

A0ABVB;00;2563;598
235649;03;2563;598
A0ABVB;00;2563;598
A0ABVB;00;2563;598

- what am i doing wrong? As what is should produce is the records in gmrd.txt that have the same second field as in core.txt
seems like the SECOND field in BOTH files is NOT UNIQUE.

what gets printed out is the LAST row from gmrd for a given SECOND field.

seems like having ONLY the second field is NOT enough to identify records UNIQUELY. You might consider either using a DIFFERENT field and/or using a combination of fields from both files to do your "lookup".
# 14  
Old 03-02-2005
is there anyway to overcome this as the only field common to both is the second field. would I have to create a variable out of the second fields in core.txt and then from that check gmrd.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question