How to pass filename as arguement to awk command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass filename as arguement to awk command?
# 1  
Old 05-06-2013
Question How to pass filename as arguement to awk command?

Hi,
I am facing one issue. The awk command works fine if i hardcode the file name but if is pass it as an arguement it doesn't work. For e.g:Below commands works fine

Code:
awk -v A="$type" '{F=substr($0,23,8) "_LTD_" A ".txt"; print $0 >> F; close(F) }' RL004.txt

But the below command does not work.
Code:
awk -v A="$type" '{F=substr($0,23,8) "_LTD_" A ".txt"; print $0 >> F; close(F) }' $path/$filename

Can you please help with this.

Last edited by Scott; 05-06-2013 at 04:23 AM.. Reason: Please use code tags
# 2  
Old 05-06-2013
What do echo $path and echo $filename say? What error message do you get when you run the awk command?
# 3  
Old 05-06-2013
Earlier I wasn't getting any error, just that splitted files were not getting created.

The command worked fine once i ran the command after going to the directory where the file is present. It is not getting executed from any other path
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I pass arguments to system command in a awk script?

Hi I need your help, please How can I pass arguments to system command in a awk script?... for example: byte=substr(cadena,pos,2); system("grep -n byte mapeo.txt"); Does it exist a way? Thanks for advance. (4 Replies)
Discussion started by: solaris21
4 Replies

2. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

3. Shell Programming and Scripting

Cannot pass rsh and awk command into a variable

Hello, I'm having some issues getting a home dir from a remote server passed to a variable. Here is what I have so far: rsh server "(ls -ld /home*/user | awk '{print \$9}')" /home3/userThat works fine and brings back what I need. But when I try to add it to a variable it goes all... (3 Replies)
Discussion started by: elcounto
3 Replies

4. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies

5. Shell Programming and Scripting

How to Pass filename to AWK in bash script

I have written a script which works fine, to remove patterns contained in EXCLUDE.DAT from input.txt awk 'BEGIN {n=0;while (getline < "EXCLUDE.DAT" > 0){ex=$0;n++}} {for(var in ex){print var "-" ex $0 ;i++}}' input.txt The last problem I need to solve is how to pass the file... (3 Replies)
Discussion started by: nixie
3 Replies

6. Shell Programming and Scripting

How to pass a filename as a command line argument

Hi,I have a script which is given below :#!/bin/bash. ini_script.shdb2 connect to $DB_NAME user $DB2_UID using $DB2_PASSWORDfor file in `ls -1 ./sql/ddw/`do echo "Executing the file $file" echo db2 -tvf $filedonedb2 quiti want this script to accept directorie's names present in... (1 Reply)
Discussion started by: ektubbe
1 Replies

7. Shell Programming and Scripting

Pass command line arguments to awk

I am trying to pass max as a sommand line argument when I call awk. Made the modification in the BEGIN but it is not working I'm getting an error as below: awk: txsrx.awk:82: (FILENAME=jcd.tx FNR=4161) fatal: cannot open file `40' for reading (No such file or directory) Somehow it... (2 Replies)
Discussion started by: kristinu
2 Replies

8. Shell Programming and Scripting

how to pass variable in NR function used in awk command?

Hi I want to pass variables with the NR function in awk command. test_file1 is input file having 500 records. var1=100. var2=200 awk -F" " 'NR >= $var1 && NR <= $var2' test_file1 > test_file2. My end result should be that test_file2 should have records from line number between... (2 Replies)
Discussion started by: Nishithinfy
2 Replies

9. UNIX for Dummies Questions & Answers

How to pass array as an arguement ?

Hi experts, I am here again with another Issue. I need to pass the array as parameter / argument to another script. I tried it as follows . ( I got this idea from the link ) $ cat test1.sh #! /usr/bin/ksh set -a arr1 echo "...In Test1...." arr1="APPS_DEV" arr1="TEST_DEV" echo... (16 Replies)
Discussion started by: rajavu
16 Replies

10. Shell Programming and Scripting

can I pass awk variable to system command?

I wanna use a system function to deal with several data. So I use awk variable FILENAME to transfer the file directory to system command, but it does not work. I use a shell function "out_function" to deal with data and save the result in another directory with the same file name. How can I... (2 Replies)
Discussion started by: zhynxn
2 Replies
Login or Register to Ask a Question