Solved

substr-awk problem

Posted on 2003-11-21
6
754 Views
Last Modified: 2013-12-26
Hi,
I am not a unix specialist but I need a script to resolve my problem. I know the algorithm but I don’t know to write this using awk in my script.
I want to have something like this:

If substr($6, length($6-1) =”_” then
TBL=$6$REG_TBL
Else
TBL=substr($6,1,18)$REG_TBL”_DM”
endif

Can somebody help my, please?
Thanks in advance
P.S.  I take $6 from rfsh.env file
0
Comment
Question by:ersatz
6 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9801954
could u post a simple example with all the values fill in.
ii can not understand the question.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9802262
> substr($6, length($6-1)
returns a string >= 0 characters
did you probably mean
  substr($6,length($6))

Then it's something like this:

{ REG_TBL_DM='irgendein ersatz'; REG_TBL='ersetzen';
  if (substr($6,length($6)) == "_"){
     TBL=$6REG_TBL
  } else {
    TBL=substr($6,1,18)$REG_TBL_DM
  }
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 9802542

I think he means ..................

if last char of $6 is "_"  then  table name will be $6$REG_TBL
otherwise It will be "first 18 char of $6" + $REG_TBL + "_DM"





0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ersatz
ID: 9807444
Hi,
You have right,I made a mistake.
My 6th column contains a variable string.
Example of this field value: F4REP_ACCOUNT_OUT_
or                            F4REP_ACCOUNT_OUT_ _DM.
REG_TBL=MMFSA
If substr($6, length($6-1), 1) =”_” then
TBL=$6$REG_TBL                      ($6 concatenate with $REG_TBL)
Else
TBL=substr($6,1,18)$REG_TBL”_DM”   (substr($6,1,18) concatenate with $REG_TBL concatenate with  "_DM"
endif
I am waiting for your answer.
Thanks again
0
 
LVL 24

Accepted Solution

by:
shivsa earned 125 total points
ID: 9807842
#!/bin/ksh
set +x

six=F4REP_ACCOUNT_OUT_
REG_TBL=MMFSA
REG_TBL_DM=MMFSA_DM

TBL=`echo "$six $REG_TBL" | awk '{
     if (substr($1,length($1)) == "_"){
     print $1 $2;
} else {
     print substr($1,1,18) $2 "_DM";
}
}'`
echo $TBL
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9816655
if the answer was just worth a B grading, what is more worth than mine?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 90
substring method in java 1 97
NotAlone Challenge 20 79
sumHeights2  challenge 7 87
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now