Can't print multiple lines inside awk :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can't print multiple lines inside awk :(
# 1  
Old 05-03-2011
Can't print multiple lines inside awk :(

Hi Friends,

I have small issue with following code snippet.

I am trying call one function inside awk in which the function inturn will echo few lines. However when i ran script its throwing an error saying "nawk: syntax error at source line 1".

Code:
#!/bin/sh
eval input=$@
 
while read line
do
        dataloader=`echo $line|nawk -F"|" '{print $1}'`
                  Chan=`echo $line|nawk -F"|" '{print $3}'`
                  coll=`echo $line|nawk -F"|" '{print $5}'`
                Datach=`echo $line|nawk -F"|" '{print $7}'`
           HAMconf=`echo $line|nawk -F"|" '{print $9}'`

functiontoAddAMGRforFTE()
{
echo  "hai"
echo  "hai2"
}

export var3="FTE."$Chan"."$coll".WORK_LIMIT=100"
nawk -v variable="$var3" '{if($0~/variable/) {print "already exist with configuration for " } else {print "'""`"functiontoAddAMGRforFTE"`""'"}}' $input
done < conffile.txt

# 2  
Old 05-03-2011
Code:
if($0~variable)

And what's the meaning of this:
Code:
{print "'""\`"functiontoAddAMGRforFTE"\`""'"}

# 3  
Old 05-05-2011
Hi,

Thanks for the reply...I have got answer for my question..

I did mistake in writing function(system - shell) which i am trying to call from AWK , hence it was throwing an error with multiple line print statement, instead i modified the script such that to call awk function inside awk script itself and it worked.

Thanks Again
SHa
# 4  
Old 05-05-2011
Code:
...
set -- $(echo $line | sed 's/|/ /g')
dataloader=$1
Chan=$3
coll=$5
Datach=$7
HAMconf=$9
...

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

2. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

(awk?) print multiple lines on one line

I have a log file something like ------- report 1 ------- date 27/01/13 time 08:00 records 1234 ------- report 2------- date 27/01/13 time 08:00 records 1239 ... I'd like output to show as report 1,date 27/01/13,time 08:00,records 1234 report 2,date 27/01/13,time... (6 Replies)
Discussion started by: gefa
6 Replies

4. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

5. Shell Programming and Scripting

AWK print lines into multiple files

Hi, i have an input text file like this: Student 1 maths science = Student 2 maths science = Student 3 maths science i would like to print each student information into separate files, each student id is separated by "=". (1 Reply)
Discussion started by: saint2006
1 Replies

6. Shell Programming and Scripting

multiple lines inside a case statement

echo "please enter ur choice.. 1. Make a file. 2. Display contents 3. Copy the file 4. Rename the file 5. Delete the file 6. Exit" read choice case $choice in 1 ) echo enter the file name read fname if then echo... (2 Replies)
Discussion started by: gotam
2 Replies

7. UNIX for Dummies Questions & Answers

print multiple lines with awk

Hi everyone! I'm not new to Unix, but I've never used awk before. I tried to look up this information on several sites and forums, I also looked in the documentation but I haven't found a solution yet. I would like to print the previous 3 lines before and the following 4 lines after the... (6 Replies)
Discussion started by: djcsabus
6 Replies

8. Shell Programming and Scripting

print argv inside awk

mode=$1 psg telnetd | awk current=`date +%M`'{ printf ("mode is %s",mode) printf ("mode is %s",ARGV) }' at command prompt when i run the script along with the argument i get only-- 'mode is ' argument is not printed.(If the argument is... (3 Replies)
Discussion started by: Anteus
3 Replies

9. Shell Programming and Scripting

variable inside awk '{print $c}'

i'm trying to do this (in bash darwin); echo "give me some words: " read a c=2 # this is get by other ways echo $a | awk '{print $c}' # i want to print the column given # by de $c variable if there is someone understand what i pretend... (3 Replies)
Discussion started by: Tártaro
3 Replies
Login or Register to Ask a Question