Execution Problem with awk command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problem with awk command
# 1  
Old 07-06-2015
Execution Problem with awk command

Hi All,

I am trying to find a word from a file in loop.

Code:
  
 while read i; do
  DB_Name=$i
  awk '{for(i=1;i<=NF;i++)if($i~/$DB_Name/)print $(i)}' $BTEQ_NAME > $DB_Name_TableList.txt
  done <Param.txt

here Param.txt contents data as
Code:
  
 ODS_TARGT_RECV
FIN_TARGT
ODS_TARGT
ODS_REP
ODS_REP_SRCE
ODS_ARCV
EDW_TARGT
EDW_REP
EDW_DATA
EDW_REP_SRCE
edw_etl_target
edw_archive
WEB_TARGT
edw_archive
WEB_DRG1_APP_SRCE

And $BTEQ_NAME is passed as BTQ_OAP_700_dI_OSTG_AP_INVC_FS.sh, In the main body.

Code:
  
 #Script Name : DB_Validation.sh
#Author : Shilpi Gupta
 clear
 DB_FIND()
 {
  IFS=$'\n' 
  set -f
  echo "=================$BTEQ_NAME=================="
  while read i; do
  DB_Name=$i
  awk '{for(i=1;i<=NF;i++)if($i~/$DB_Name/)print $(i)}' $BTEQ_NAME > $DB_Name_TableList.txt
  done <Param.txt
 
  
}
  
 # Main Body of this Script
 BTEQ_NAME_LIST=$1
BTEQ_PARAM_FILE=$2
 awk '{for(i=1;i<=NF;i++)if($i~/\=/)print $(i)}' $BTEQ_PARAM_FILE|cut -d"=" -f1 > ParamP1.txt
 awk '{for(i=1;i<=NF;i++)if($i~/_/)print $(i)}' ParamP1.txt > Param.txt
 rm ParamP1.txt
 awk '{for(i=1;i<=NF;i++)if($i~/\=/)print $(i)}' $BTEQ_PARAM_FILE|cut -d"=" -f2 > ParamVal1.txt
 awk '{for(i=1;i<=NF;i++)if($i~/_/)print $(i)}' ParamVal1.txt > ParamVal.txt
 rm ParamVal1.txt
 for i in `cat ${BTEQ_NAME_LIST}` ; do
BTEQ_NAME=`echo "${i}" | awk -F"|" '{ print $1 }'`;
export BTEQ_NAME;
 DB_FIND
done


But while executing the script getting error as:
Code:
  
 awk: can't open BTQ_OAP_700_dI_OSTG_AP_INVC_FS.sh
 :
 :

Please let me Know where I am doing wrong...

Thanks,

Shilpi Gupta

Last edited by vbe; 07-06-2015 at 09:51 AM.. Reason: extra code tags...
# 2  
Old 07-06-2015
We dont know just by looking at your code like that... You should ask yourself why cant awk open that file:
- Where are you when executing the script, is the script present where your are...
- Who are you when executing the script and what are the permissions on that file...
# 3  
Old 07-06-2015
Hi vbe

I am getting error when using variable under awk command
Code:
  
 awk '{for(i=1;i<=NF;i++)if($i~/$DB_Name/)print $(i)}' $BTEQ_NAME > ${DB_Name}_TableList.txt


But able to get the result when hard coding the variable like :

Code:
  
 
 awk '{for(i=1;i<=NF;i++)if($i~/\$ODS_REP_SRCE/)print $(i)}' BTQ_OAP_700_dI_OSTG_AP_INVC_FS.sh > ODS_REP_SRCE_TableList.txt

And here the file have all permission.

As I am new to shell script, so not able to debug.
# 4  
Old 07-06-2015
Code:
 awk '{for(i=1;i<=NF;i++)if($i~/$DB_Name/)print $(i)}' $BTEQ_NAME > ${DB_Name}_TableList.txt

$DB_Name does not expand as you expect.
Code:
awk -v target=$DB_Name '{for(i=1;i<=NF;i++)if($i ~ target)print $(i)}' $BTEQ_NAME > ${DB_Name}_TableList.txt

# 5  
Old 07-06-2015
Thanks Aia for your response..
But now getting error as

Code:
  
 awk: syntax error near line 1
awk: bailing out near line 1

# 6  
Old 07-06-2015
We need also know your OS and version of OS , and the shell you are using...
awk behaviour and syntax may vary depending implementation...
# 7  
Old 07-07-2015
That diagnostic message is common on Solaris/SunOS systems when using /usr/bin/awk. If you are using a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk in your script and try again.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk execution problem in csh

This has no error awk '($8==150) && ($4>=11.001 && $4 <= 12) && ($5>=91.001 && $5<=92){print}' OFS="\t" file following are unable to run in csh this is giving error awk: line 1: syntax error at or near not even working in terminal awk '($'$gr'=='$grn') && ($'$ll'>='$Y' && $'$ll' <= '$Ym')... (1 Reply)
Discussion started by: nex_asp
1 Replies

2. Shell Programming and Scripting

Multiple command execution inside awk command during xml parsing

below is the output xml string from some other command and i will be parsing it using awk cat /tmp/alerts.xml <Alert id="10102" name="APP-DS-ds_ha-140018-componentFailure-S" alertDefinitionId="13982" resourceId="11427" ctime="1359453507621" fixed="false" reason="If Event/Log Level(ANY) and... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Linux

Execution problem wid mpstat command

mpstat -P ALL 1 10 it results.. 08:05:54 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s 08:05:55 PM all 0.00 0.00 0.49 0.00 0.49 0.00 0.00 99.02 1024.75 08:05:55 PM 0 0.00 0.00 0.00 0.00 0.99 0.00 0.00 ... (1 Reply)
Discussion started by: pritesh_patil
1 Replies

4. Shell Programming and Scripting

getting problem in awk command

Hi, I have one file with tab delimited values in it. i want to increase the value of 6th field by 2 if value of 3rd field is greater than 2 . The command is working fine but space between the field is getting removed after adding. below is the file and the command Filename: test1.txt ... (13 Replies)
Discussion started by: ravi_agarwalla
13 Replies

5. Shell Programming and Scripting

problem with awk command

I have written some code in a KSH script to find the index of the character in a string like this #!usr/bin/ksh string="Hi How are you" awk 'BEGIN {print index ($string, "are")}' My expected output should be : 8 but it is giving the out put as : 0 I wanted to store that index value in... (8 Replies)
Discussion started by: hemanth424
8 Replies

6. Shell Programming and Scripting

problem with awk command

I am having problem running an awk commad on a file Before applying awk command on the file After applying I don't expect more than 409743 records in the file. Why do I have 1 record more after applying awk command? Please let me know (4 Replies)
Discussion started by: dsravan
4 Replies

7. Shell Programming and Scripting

Execution problems using awk command.

Hi All, I have the following requirement. In a directory i get files from external source. I at regular intervals check that directory for any incoming files. The file name is underscore delimited. Such as: aaa_bbb_ccc_ddd_eee_fff.dat I am using awk and and splitting the file name. ... (4 Replies)
Discussion started by: satishpv_2002
4 Replies

8. Post Here to Contact Site Administrators and Moderators

AWK command problem

How can I write an AWK so it could print some fixed strings and concatenate that with other words from an input file. Also having a string like "go" in the next line in the output file as below: Example: A fixed string like: "Hello my" and the input file is: friend mother father... (4 Replies)
Discussion started by: sybase08
4 Replies

9. Shell Programming and Scripting

Execution of awk command in a variable

Hi All, I have a awk command that is stored in a variable. the value of the variable cmd is: (mean output of echo $cmd is: ) awk -F";" '{print $1}' Now I want to execute this command. How can I do that???? Quick Reply will be appreciated. Regards, Amit (2 Replies)
Discussion started by: patelamit009
2 Replies

10. Shell Programming and Scripting

problem in awk command

Hello all, i am new one to this forum. : i have file with these contents.. internal://project/squid-internal-static/icons/anthony-xpm.gif http://widget.blogrush.com/img/br.png http://www.wingware.com/css/print http://publib.boulder.ibm.com/infocenter/systems/advanced/filterwarning.css... (3 Replies)
Discussion started by: viveksnv
3 Replies
Login or Register to Ask a Question