![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Storing commands in $variables. | Paulw0t | Shell Programming and Scripting | 7 | 08-08-2008 05:42 PM |
| Splitting the data and storing it into 2 variables | jisha | Shell Programming and Scripting | 10 | 02-17-2008 10:40 PM |
| Help - Setting variables equal to data from another file | Crios121 | UNIX for Dummies Questions & Answers | 1 | 03-05-2007 12:40 PM |
| Storing data of files | Fr0z3n999 | UNIX for Dummies Questions & Answers | 1 | 12-09-2006 09:47 PM |
| first row data into variables | u263066 | Shell Programming and Scripting | 1 | 08-14-2006 07:54 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk - storing multiple line data in variables
Hi Ygor,
I created the following file <<t1.awk>> BEGIN{FS = "|"; RS = "\n"} NR==2{print $1, $2} | read var1 var2 echo $var1 ' ' $var2 as my data is "|" delimited then from $prompt I am writing: awk -f t1.awk abc.flag (my source file) it gives me an error: awk: syntax error at source line 2 source file t1.awk context is NR==2{print $1, $2} >>> | <<< read var1 var2 awk: bailing out at source line 4 Please help Thanks in advance |
|
||||
|
awk - storing multiple line data in variables
Hi Ygor,
Thanks for your prompt help. Can we read the files form line 1 and 2 at one attempt through awk? individually I am able to read the lines and redirect to variables. Can I read both the lines together and redirect to 6 variables (I am refering to the file layout that you gave as example: a|b|c 1|2|3 x|o|p my t1.awk now looks as follows: BEGIN{FS = "|"; RS = "\n"} NR==2{print $1, $2 $3} NR==1{print $1, $2} then I wrote: awk -f t1.awk abc.flag | read - and then I got confused as the $1 and $2 variables will overwrite the previous $1 and $2 variables. How do I retain the values that I have read in the first line - (NR==2{print $1, $2 $3}) and then go over to the next line. Hope I cud explain. Regards, Nilotpal. |
|
||||
|
awk - storing multiple line data in variables
hi Ygor,
Thanks for the assistance. I am able to use the local variable approach (j=$1...) but not the array approach. The arracy approach is taking the entire string 'awk -f t1.awk abc.flag' as an argument and not the output of awk awk -f t1.awk abc.flag My t1.awk now looks like: BEGIN{FS = "|"; RS = "\n"} NR==1{j=$1;k=$2} NR==2{print j, k, $1, $2, $3} then $ awk -f t1.awk abc.flag gives me: a b 1 2 3 on the console. How can I capture this console output so that I can use them in a shell script to insert into a oracle table? I guess I cannot do database activities (insert/select) within a AWK script. My Insert shell script is: sqlplus $USERNAME/$PASSWD@clbd << END insert into nr_test (COL1, COL2, COL3, COL4, COL5 ) VALUES ('$var1', '$var2', $var3, $var4, '$var5); EXIT; END so typically i need the data in the awk variables j,k,$1, $2, $3 to be acceptted into $var1', '$var2', $var3, $var4, '$var5 Please advice. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|