Sponsored Content
Top Forums Shell Programming and Scripting Parsing a file and setting to variables. Post 302993967 by jeffs42885 on Thursday 16th of March 2017 07:11:08 PM
Old 03-16-2017
Quote:
Originally Posted by RudiC
Post#7 is quite misleading. After rereading and rereading, the last code tagged block seems to be the config/jeff.awk script to be run by awk. The first line looks like it is meant to "source" /location/to/properties/file/config.file, which is a bash (or, generally, shell) builtin. Of course, awk doesn't understand this and errors out accordingly.
And, not sure why you think you need those variables - they're not used anywhere.
Apologies for this being misleading, allow me try and attempt to clarify.

You answered my question in this post. I am trying to source the config file just like I would do in a normal shell script. Obviously, that is one thing that is not working.

Code:
BEGIN {
  FS=OFS=","
  qq="\""
  printf("<application name=%s$FIELD1%s>\n\t<field task=%supdate%s name=%s$FIELD2%s>\n", qq, qq,qq,qq,qq,qq)
}
{printf("\t<mapping db=%s%s%s displayed=%s%s%s />\n", qq, $1, qq, qq, $2, qq)}
END {
  printf("\t</field>\n</application>\n")
}

When I remove the "sourcing" at the top of the file, this generates the XML like I expect it to, with the value of application name set as FIELD1, and the value of field name set as FIELD2.

It might have been clearer if I could code a config file to be read from this awk script, much like I have the shell script reading from. I hope this makes sense. Thank you for the clarification and any further assistance.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-17-2017 at 05:42 AM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting variables in a function

I'm not quite sure what I'm doing wrong here. I've go several jobs which print reports. Occassionally a printer will break down and reports need to be move to another printer. Rather than hard code the printer names in our scripts I'm trying to set these programatically using our function... (1 Reply)
Discussion started by: BCarlson
1 Replies

2. Shell Programming and Scripting

Parsing and getting values of variables

suppose i have a file value where it returns 3 values a=1 b=2 c=4 when i run it. i am using this file in my shell script. how do i parse and get the value of a b and c? (3 Replies)
Discussion started by: Rekha
3 Replies

3. UNIX for Dummies Questions & Answers

Help - Setting variables equal to data from another file

Relatively new poster but long time reader. I tried searching all threads for similar situations with mine but I've had no luck with some of the solutions. I have a script (script.ksh) that is getting information from an Oracle DB and spooling it into a text file (log.txt). I would then like... (1 Reply)
Discussion started by: Crios121
1 Replies

4. UNIX for Advanced & Expert Users

setting some variables

i have a file .NAMEexport MY_NAME=JOE when i do this at the command prompt #. .NAME $echo MY_NAME $JOEi created a script called Run.sh . .NAME At the command prompt i did #sh Run.sh #echo $MY_NAMEit returns nothing. What have i missed out? (7 Replies)
Discussion started by: new2ss
7 Replies

5. UNIX for Dummies Questions & Answers

Setting up variables

Hi all, I have a shell script that sets up the environment for an application running on UNIX - ksh. This script is run using: . ./script_name XX where XX is a parameter. I want to run it from another shell script but when I do it I don't get the envornment variables set up and the prompt... (3 Replies)
Discussion started by: solar_ext
3 Replies

6. Shell Programming and Scripting

Perl: parsing variables

I have the following script: #!/usr/bin/perl -w @files = <*.csv>; foreach $file (@files) { open(FH, $file); my @dt = split(/_|.csv/, $file); while (<FH>) { chomp; print $dt . $dt . ",$_\n"; } close(FH); } This script reads in all csv files in the current directory... (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

Setting environment variables in Cron file

Hi, In Cron file i'm using username and password hard-coded and now i wann to use environmental veraiables in cron file. But Could you please guide me how to use these environmental variables in cron file ? Thanks, Shyamu.A (4 Replies)
Discussion started by: shyamu544
4 Replies

8. UNIX for Dummies Questions & Answers

Parsing alphanumeric variables

Hi All, I have files with a column which has values and ranges, for example colA colB ERD1 3456 ERD2 ERD3 4456 I want to have the following output colA colB colC ERD1 3456 3456 ERD2 526887 526890 ERD3 4456 4456 Being a newbie to... (2 Replies)
Discussion started by: alpesh
2 Replies

9. Shell Programming and Scripting

Setting environment variables from a file :

Hi, I have around 10 environment variables in my shell script. i want to set this all in a file and just call that file in my shell script. How can i do that ? Please help. TIA! (6 Replies)
Discussion started by: qwertyu
6 Replies

10. Shell Programming and Scripting

Parsing fields into variables

A record contains 50 fields separated by "~". I need to assign each of these fields to different variables. Following is the shell script approach I tried. RECORD="FIELD1~FIELD2~FIELD3~FIELD4~FIELD5~...........~FIELD50" VAR1=$(echo ${RECORD} | cut -d"~" -f 1) VAR2=$(echo ${RECORD} | cut... (5 Replies)
Discussion started by: krishmaths
5 Replies
All times are GMT -4. The time now is 11:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy