11-02-2010
ok so I modified my shell script like this:
-------------------------------------------
#!/usr/bin/sh
#---------------------------------------------------------------------
# Program ....... dups_filter.sh
pos="$1"
filename="$2"
awk -v key="$pos" -v infile="$filename" '{FS="";split($NF,a,"_"); site=a[3];keysite=key "_" site;
if (b[keysite]<=a[4]a[5]) {b[keysite]=a[4]a[5];c[keysite]=$0;}}
END{for (i in b) print c[i]}' infile
#end of .sh program
---------------------------------------------------------------
I have the .sh script in the same directory as the infile dups.txt.
I execute from the command line like:
./rem_dups.sh 1 dups.txt > no_dups.txt
and I get the error
awk: Cannot find or open file infile.
The source line number is 3.
Could somebody help me with this confusion?
Last edited by script_op2a; 11-02-2010 at 06:33 PM..
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I have a shell script with an ambedded awk script.
i need to pass a script variable to the awk script.
Please help.
Thanks in advance
Himani (3 Replies)
Discussion started by: HIMANI
3 Replies
2. UNIX for Dummies Questions & Answers
Hey Guys
from the below script what I understood is we are sending the the first parameter as input to the main (){} file
main > $LOGFILE 2>&1
but can we send two or three parameter as input to this main file as
main > $LOGFILE 2>&1 2>&2 like this
Can any one plz help I need to writ a... (0 Replies)
Discussion started by: pinky
0 Replies
3. Shell Programming and Scripting
Hello experts,
can I return a value from gawk to a shell script ?
My script as follows,
#Here I want the num value to shell script so that I can use later
gawk '
{
split($0,num,",");
print num
}'
gawk -v no=$number '{print no}'
file1
... (3 Replies)
Discussion started by: user_prady
3 Replies
4. Shell Programming and Scripting
Hello Experts,
Actually I was searching for a solution here in this forum , but didn't get what exactly I want . Is this possible to do in awk ?
I am trying to do some thing like below in ksh script . Upto my knowledge I can pass shell script to awk with "-v " option.
But I... (3 Replies)
Discussion started by: user_prady
3 Replies
5. Shell Programming and Scripting
I have a working and tested AWK script that removes duplicates from an input file and generates an output file without the duplicates.
I had help from my other post to develop it:
... (3 Replies)
Discussion started by: script_op2a
3 Replies
6. Shell Programming and Scripting
Hi,
I basically have 2 shell scripts.
One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system.
Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn.
... (2 Replies)
Discussion started by: sunrexstar
2 Replies
7. Shell Programming and Scripting
Why does this work
for myfile in `find . -name "R*VER" -mtime +1`
do
SHELLVAR=`grep ^err $myfile || echo "No error"`
ECHO $SHELLVAR
done
and outputs
No error
err ->BIST Login Fail 3922 err
No error
err ->IR Remote Key 1 3310 err
But... (2 Replies)
Discussion started by: alan
2 Replies
8. Post Here to Contact Site Administrators and Moderators
Variable I have in my shell script
diff=$1$2.diff
id=$2
new=new_$diff
echo "My id is $1"
echo "I want to sync for user account $id"
##awk command I am using is as below
cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new
I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies
9. Shell Programming and Scripting
I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist.
diff=$1$2.diff
id=$2 new=new_$diff
echo "My id is $1"
echo "I want to sync for user account $id"
##awk command I am using is as below
cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies
10. Shell Programming and Scripting
Hi,
Please need to print the Rej variable outsite the awk script which is given below...please advised how to achieve it.
#!/bin/bash
echo "Enter DMU Pipe delimited File name for the Feed to be validated"
read DMU_File
echo "Enter Pre-DMU File name for the Feed"
read Predum_file
... (3 Replies)
Discussion started by: pelethangjam
3 Replies
LEARN ABOUT DEBIAN
array_allocate
array_allocate(3) Library Functions Manual array_allocate(3)
NAME
array_allocate - make sure array has at least n elements allocated
SYNTAX
#include <array.h>
void* array_allocate(array* x, uint64 membersize, int64 pos);
array x;
int64 pos;
t* p = array_allocate(&x,sizeof(t),pos);
DESCRIPTION
array_allocate makes sure that enough bytes are allocated in x for at least pos+1 objects of type t. (The size of t must be positive; oth-
erwise the effects are undefined.) If not enough bytes are allocated (or x is unallocated), array_allocate allocates more bytes, moving the
dynamically allocated region if necessary. array_allocate often allocates somewhat more bytes than necessary, to save time later.
array_allocate then makes sure that the number of bytes initialized covers at least those pos+1 objects. If not enough bytes are initial-
ized, array_allocate initializes more bytes (setting them to 0), up to exactly the end of the pos+1st object.
array_allocate then returns a pointer to the pos+1st object; i.e., object number pos, with objects numbered starting at 0. This pointer can
be used to change or inspect the object. The pointer can continue to be used through subsequent calls to array_get, array_start,
array_length, and array_bytes, but it must not be used after any other operations on this array.
If something goes wrong, array_allocate returns 0, setting errno appropriately, without touching x. In particular, array_allocate returns 0
if
o x has failed, or
o pos is negative, or
o not enough memory is available.
array_allocate does not change x to have failed; if you want to do that, use array_fail.
SEE ALSO
array_get(3), array_start(3), array_fail(3)
array_allocate(3)