Need help to convert syntax to shell

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need help to convert syntax to shell
# 1  
Old 10-22-2016
Need help to convert syntax to shell

Hi Folks -

I need help converting a piece of code from batch to bash.

Here is the code:

Code:
FOR    /f "eol=; tokens=1,2,3,4 delims=, " %%i in (Update_Subvars.txt) do (

    ECHO alter database %%i.%%j set variable %%k %%l;

)

What it's doing is retrieving the values from this file:

Code:
GENJBAPP,Fin_Plan,ActMonth,Nov    
GENJBAPP,Fin_Plan,BudYear,FY18
GENJBAPP,Fin_Plan,CurrMonth,Nov
GENJBAPP,Fin_Plan,CurrYear,FY17
GENJBAPP,Fin_Plan,CurrYear1,FY18
GENJBAPP,Fin_Plan,CurrYear2,FY19
GENJBAPP,Fin_Plan,FcstMonth,Dec
GENJBAPP,Fin_Plan,PriorMonth,Oct
GENJBAPP,Fin_Plan,PriorYear,FY16

Thank you!
# 2  
Old 10-22-2016
Hi,
Maybe in pure bash:
Code:
$ while IFS="," read a b c d; do printf "alter database $a.$b set variable $c $d;\n"; done <Update_Subvars.txt 
alter database GENJBAPP.Fin_Plan set variable ActMonth Nov;
alter database GENJBAPP.Fin_Plan set variable BudYear FY18;
alter database GENJBAPP.Fin_Plan set variable CurrMonth Nov;
alter database GENJBAPP.Fin_Plan set variable CurrYear FY17;
alter database GENJBAPP.Fin_Plan set variable CurrYear1 FY18;
alter database GENJBAPP.Fin_Plan set variable CurrYear2 FY19;
alter database GENJBAPP.Fin_Plan set variable FcstMonth Dec;
alter database GENJBAPP.Fin_Plan set variable PriorMonth Oct;
alter database GENJBAPP.Fin_Plan set variable PriorYear FY16;

Or with awk:
Code:
$ awk -F\, '{printf("alter database %s.%s set variable %s %s;\n",$1,$2,$3,$4)}' Update_Subvars.txt
alter database GENJBAPP.Fin_Plan set variable ActMonth Nov;
alter database GENJBAPP.Fin_Plan set variable BudYear FY18;
alter database GENJBAPP.Fin_Plan set variable CurrMonth Nov;
alter database GENJBAPP.Fin_Plan set variable CurrYear FY17;
alter database GENJBAPP.Fin_Plan set variable CurrYear1 FY18;
alter database GENJBAPP.Fin_Plan set variable CurrYear2 FY19;
alter database GENJBAPP.Fin_Plan set variable FcstMonth Dec;
alter database GENJBAPP.Fin_Plan set variable PriorMonth Oct;
alter database GENJBAPP.Fin_Plan set variable PriorYear FY16;

Regards.
# 3  
Old 10-22-2016
Thank you, sir! That's beautiful!

Now, how would I pipe it into this command?

Code:
    ECHO alter database %%i.%%j set variable %%k %%l; | %STARTMAXL% -s %ESSB_SRVR% -l %ESSB_USER% %ESSB_PSWD% -i

The above is how I do it in batch.

Code:
while IFS="," read a b c d; do printf "alter database $a.$b set variable $c $d;\n"; done <Update_Subvars.txt | $STARTMAXL -s $ESSB_SRVR -l $ESSB_USER $ESSB_PSWD -i

I tried to do it above, is that correct?

Thanks!

Last edited by Don Cragun; 10-22-2016 at 07:02 PM.. Reason: Add CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error C shell

Hello, I have a newbe syntax error but I cant find it syntax error: unexpected end of file #!/bin/csh # pe request #$ -pe mpi_16 32 #### 16 core : 'mpi_16 16' || 24 core : 'mpi_24 24 ' # our Job name #$ -N test2MD #$ -S /bin/sh (1 Reply)
Discussion started by: dulceC
1 Replies

2. Shell Programming and Scripting

Shell scripting syntax

mydate ="$(date)" what is the use of adding double code and parenthesis in the above code .. can i write the same code as mydate= $date (5 Replies)
Discussion started by: lobsang
5 Replies

3. UNIX for Dummies Questions & Answers

Unable to convert date into no. using date -d +%s syntax in ksh shell

hi friends, I m trying to write a script which compares to dates. for this i am converting dates into no using synatx as below v2=`date | awk '{print $2,$3,$4}'` v3=`date +%s -d "$v2"` this syntax is working in bash shell ,but fails in ksh shell. please suggest on this. (12 Replies)
Discussion started by: Jcpratap
12 Replies

4. Shell Programming and Scripting

Shell advanced syntax?

I am not an expert of shell scripting, but I can do some simple things. Now, I read a script written by others and I need some help from the experts of this forum. Please help me to understand what is going on in this cycle: if ; then ] && \ export... (25 Replies)
Discussion started by: alt
25 Replies

5. Shell Programming and Scripting

Help Syntax Shell-Script

Hi Guys, iīve a question ... but itīs a litte bit tricky: iīve a 3 php-scripts which runīs via cron at night. These script reads an xml-file a writes it in an MySQL-DB. I named them (for example here ) Script1 - Script3. The XML-Files i named xml1 - xml3. Now, iīve build a Batch-file,... (10 Replies)
Discussion started by: jackcracker
10 Replies

6. Shell Programming and Scripting

syntax of c shell

i have this program in bash shell: #!/bin/bash array=(20 20 20 20 20) i=0 j=0 awk '/%/ {print $3}' try.txt| while (read s) arr=$s i=`expr $i + 1` echo "$i" end how can i convert this into c shell? (1 Reply)
Discussion started by: npatwardhan
1 Replies

7. Shell Programming and Scripting

Shell syntax

I'm having simple question here, and what's the different here? What is the "x" for? Thanks! (5 Replies)
Discussion started by: redstone
5 Replies

8. UNIX for Dummies Questions & Answers

Help with a shell syntax

I have a variable named "xyz" Now what will the below snippet mean: if ( ${?xyz} ) then .... endif What does ? signify here. Thanks (12 Replies)
Discussion started by: vibhor_agarwali
12 Replies

9. Solaris

C-shell: variable syntax question

There is a possibility to set a variable, having an another variable in it's name: prompt% setenv PRT one prompt% setenv VAR_${PRT} value prompt% So, this way the VAR_one = "value" and could be viewed: prompt% echo VAR_one value prompt% Q: How to view a variable having another... (0 Replies)
Discussion started by: alex_5161
0 Replies

10. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies
Login or Register to Ask a Question