specified path name is too long passing parameters to awk via shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting specified path name is too long passing parameters to awk via shell script
# 1  
Old 11-09-2010
specified path name is too long passing parameters to awk via shell script

Hello,

I have this shell script that runs awk code by passing in parameters however now it doesn't work anymore with the parameters and I don't know why.

It removes duplicates from an input file based on a part of the last field and a key column. It removes the record with the older datetime in the last column.


In this case the key column of the input file is the first column (so 1).

Input file

Code:
1238646010001529 A cmt_det3_937_20101024_065520.txt
1239560010002084 A cmt_det3_937_20101024_065520.txt
1240650010013664 A cmt_det3_937_20101024_065520.txt
1238646010001529 B cmt_det3_937_20101025_065520.txt
1239560010002084 B cmt_det3_937_20101025_065520.txt
1240650010013664 B cmt_det3_937_20101025_065520.txt

The shell script:
Code:
#!/usr/bin/sh

pos=$1
infile="$2/$3"
outfile="$4/$5"

if [[ ! -r $infile ]]
then
        echo "file is not readable: $infile"
        exit 1
fi

# pass the key position using -v
awk -v key_col="$pos" 
    '{    
        FS="";
        split($NF,a,"_"); 
                site=a[3];
                keysite=$(key_col) "_" 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 > $outfile

I run it on the Unix command line like this:

Code:
./remove_dups.sh 1 . input.txt . out.txt

I get this error message:

Code:
./remove_dups.sh[32]: {^I^J^I^IFS="^_";^J^I^Isplit($NF,a,"_"); ^J
 site=a[3];^J                keysite=$(key_col) "_" site;^J                if (b
[keysite]<=a[4]a[5]) ^J                {^J                        b[keysite]=a[4
]a[5];^J                        c[keysite]=$0; ^J                }^J^I}  ^J^J
     END{^J                for( i in b ) ^J                ^I^J^I^Iprint c[i];^J
^J        }: The specified path name is too long.

---------- Post updated at 07:03 PM ---------- Previous update was at 06:39 PM ----------

problem solved

had to remove the space between

Code:
< $infile > $outfile

Like this works.

Code:
<$infile >$outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to run sql query having a long listing of parameters

Hi, I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script. The scenario is like.... Suppose I have a file abc.txt that has the card numbers..it could be in thousands.. then I need to fire a query like ... (12 Replies)
Discussion started by: vsachan
12 Replies

2. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

3. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

4. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

5. Shell Programming and Scripting

passing parameters using awk

Hi, The below script is working fine awk1.sh ======= awk BEGIN { FS="|" } FNR==NR { f1=$2; next } $1 in f1 && $2 =="xx" && $1 == "DAILY_JOB" {print $3} awk -f awk1.sh a.txt b.txt--Its working fine . When passing parameters its not working .Any help it should be appereciated. ... (4 Replies)
Discussion started by: akil
4 Replies

6. Shell Programming and Scripting

Shell Script Passing Parameters For Directory Listing

i have this basic piece of code that i am trying to debug to accept input parameter to be able to display a directory listing of files. cd /u02/app/eatv/dev/out CURDIR=`pwd` echo directory listing of $CURDIR echo if ; then ls -latr else ls -latr $1 fi basically if the script... (9 Replies)
Discussion started by: wtolentino
9 Replies

7. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

8. Shell Programming and Scripting

passing oracle parameters back to Shell

Hi All, Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure: eg #username='scott' #password='tiger' #database='orcl' username='ITGCD03D03' password='tC5epIew' database='ITGCD03D' sqlplus -s... (4 Replies)
Discussion started by: satnamx
4 Replies

9. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

10. Shell Programming and Scripting

passing parameters from a shell script to sqlplus

Hi , I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script Right now no file is generated on the unix box...it is a... (2 Replies)
Discussion started by: phani
2 Replies
Login or Register to Ask a Question