Sponsored Content
Top Forums Shell Programming and Scripting Challenging Awk array problem Post 302423795 by polsum on Saturday 22nd of May 2010 12:25:24 PM
Old 05-22-2010
Quote:
Originally Posted by alister
Here's a simpler approach that only uses AWK (and which I should've suggested from the beginning):
Code:
awk '{chr=$6; min=$7; max=$8; s=$11" "$12" "$13; getline < f2; if (chr==$4 && $5>=min && $5<=max) print $0, s;}' f2='file2' file1

You can change what's in red to suit your needs, but leave the rest as is.

Changing the quotes as you say you did completely changes the meaning of the code; using double quotes at the outer level causes every instance of a dollar sign folowed by a digit to be expanded by the shell instead of being passed literally to AWK for its use. AWK will never see them. Also, you are altering what is quoted and what is not quoted by creating unintended quoted strings with the double quotes that were embedded in the single quotes which were removed.

Alister
Alister, thanks for the code. But when I run it, it gives me an error message "the system can not find the file specified" even though the files are in the installation directory.

Also, while running other scripts I always use double quotes and it works fine. Single quotes doesn't work in my windows laptop. They work fine in my ubuntu office computer though.

It might be easier to run this in a script with -f option, but then the code might have to be changed a bit at the end so that the files will be given as in put in the command prompt. Here file 1 can be removed from the script and put in the command prompt but not sure how file2 should be accommodated.

Last edited by polsum; 05-22-2010 at 01:50 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

A Challenging Situation : i hope the moderators will respond to this problem..

I have the following situation : i have 4 Unix Sco servers, one Windows 2000 server, and an ADSL internet connection. All the servers, that is the 4 unix and the windows server have real static IPs supplied by my ISP. the servers are connected to a Switch , the switch is connected to an... (2 Replies)
Discussion started by: BAM
2 Replies

2. Programming

A challenging problem involving symbolic links.

Hello, I'm working on an application that bridges together several applications involved in creating a video workflow for editing with digital cinema cameras. The main platform is MacOSX. Because of the nature of some of the utilities for working with this video footage I must spoof filenames... (2 Replies)
Discussion started by: ibloom
2 Replies

3. Shell Programming and Scripting

Very Challenging Problem. Please read fully.

Hi, This is the Third thread i'm putting here for the same problem. :( Actually, i'm trying a script like this.. but its taking a long time.. about 3 days to complete fully.. #!/bin/ksh if then exit 1 fi while read i do while read j do field7=`echo $j|cut -d "|"... (12 Replies)
Discussion started by: RRVARMA
12 Replies

4. Shell Programming and Scripting

awk array problem

hi i am trying to perform some calculations with awk and arrays. i have this so far: awk 'NR==FNR{ for(i=1; i<=NF; i++) {array+=$i} tot++;next} {for(i=1; i<=NF; i++) {avg=array/tot} {diff=(array - avg)}} {for(i=1; i<=NF; i++) {printf("%5.8f\n",diff)}}' "$count".txt "$count".ttt >... (4 Replies)
Discussion started by: npatwardhan
4 Replies

5. Shell Programming and Scripting

Problem with lookup values on AWK associative array

I'm at wits end with this issue and my troubleshooting leads me to believe it is a problem with the file formatting of the array referenced by my script: awk -F, '{if (NR==FNR) {a=$4","$3","$2}\ else {print a "," $0}}' WBTSassignments1.txt RNCalarms.tmp On the WBTSassignments1.txt file... (2 Replies)
Discussion started by: JasonHamm
2 Replies

6. Shell Programming and Scripting

AWK Array problem

Dear All, I am facing problem to get right output through awk program I have file in which “B” value is appearing multiple time and I need to capture all these values. My script is BEGIN { FS=" " } { if ( substr($1,1,5) == "START" ) { i =... (2 Replies)
Discussion started by: arvindng
2 Replies

7. Shell Programming and Scripting

awk array problem

Hi, Im trying to count bats flying through an infrared beam array. One of the experts here helped me a few months ago but now I am having a problem that is stumping me. here is the original code that works (with two differnt patterns in array): # this has been changed to operate under the... (15 Replies)
Discussion started by: cmp260
15 Replies

8. Shell Programming and Scripting

Using awk array problem

I am trying to map values in the input file, where 2nd column depends on the specific value in the 1st column. When 1st column is A place 1 into 2nd column, when it is B, place 2, when C place 3, otherwise no change. My input: U |100|MAIN ST |CLMN1|1 A |200|GREEN LN |CLMN2|2 1 |12... (4 Replies)
Discussion started by: migurus
4 Replies

9. Shell Programming and Scripting

Problem with awk array when loading from shell variable

Hi, I have a problem with awk array when iam trying to use awk in solaris box as below..Iam unable to figure out the problem.. Need your help. is there any alternative to make it in arrays from variable values nawk 'BEGIN {SUBSEP=" "; split("101880|110045 101887|110045 101896|110045... (9 Replies)
Discussion started by: cskumar
9 Replies

10. Shell Programming and Scripting

Index problem in associate array in awk

I am trying to reformat the table by filling any missing rows. The final table will have consecutive IDs in the first column. My problem is the index of the associate array in the awk script. infile: S01 36407 53706 88540 S02 69343 87098 87316 S03 50133 59721 107923... (4 Replies)
Discussion started by: yifangt
4 Replies
TCATEST(3)							   Tokyo Cabinet							TCATEST(3)

NAME
tcamgr - the command line utility of the abstract database API DESCRIPTION
The command `tcamgr' is a utility for test and debugging of the abstract database API and its applications. `name' specifies the name of a database. `key' specifies the key of a record. `value' specifies the value of a record. `params' specifies the tuning parameters. `func' specifies the name of a function. `arg' specifies the arguments of the function. `dest' specifies the path of the destination file. tcamgr create name Create a database file. tcamgr inform name Print miscellaneous information to the standard output. tcamgr put [-sx] [-sep chr] [-dk|-dc|-dai|-dad] name key value Store a record. tcamgr out [-sx] [-sep chr] name key Remove a record. tcamgr get [-sx] [-sep chr] [-px] [-pz] name key Print the value of a record. tcamgr list [-sep chr] [-m num] [-pv] [-px] [-fm str] name Print keys of all records, separated by line feeds. tcamgr optimize name params Optimize a database file. tcamgr misc [-sx] [-sep chr] [-px] name func [arg...] Call a versatile function for miscellaneous operations. tcamgr map [-fm str] name dest Map records into another B+ tree database. tcamgr version Print the version information of Tokyo Cabinet. Options feature the following. -sx : the input data is evaluated as a hexadecimal data string. -sep chr : specify the separator of the input data. -dk : use the function `tcadbputkeep' instead of `tcadbput'. -dc : use the function `tcadbputcat' instead of `tcadbput'. -dai : use the function `tcadbaddint' instead of `tcadbput'. -dad : use the function `tcadbadddouble' instead of `tcadbput'. -px : the output data is converted into a hexadecimal data string. -pz : do not append line feed at the end of the output. -m num : specify the maximum number of the output. -pv : print values of records also. -fm str : specify the prefix of keys. This command returns 0 on success, another on failure. SEE ALSO
tcatest(1), tcamttest(1), tcadb(3), tokyocabinet(3) Man Page 2012-08-18 TCATEST(3)
All times are GMT -4. The time now is 09:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy