get substring from string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get substring from string
# 1  
Old 07-08-2009
get substring from string

Hi All,

Problem Description:
Code:
XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME" 
"CP_SHORT_NAME"`
echo Report Request: $XML_REP_REQUEST  --to print value in log file

While execution the value of 'XML_REP_REQUEST' is 'Prozess "4479620" für "CONCURRENT TEST_REPORT " gestartet Normal beendet'
I am storing the sub string '4479620' of variable XML_REP_REQUEST in variable 'XML_REP_REQUEST' using code below:
Code:
XML_PUB_REQUEST_ID=`echo $XML_PUB_REQUEST |tr -s " "| cut -d" " -f2|tr -d """`

But it's returning "4479620" instead of 4479620.

Any idea where I am going wrong Smilie

Many thanks,
Suman

---------- Post updated at 02:05 AM ---------- Previous update was at 01:38 AM ----------

topic changed...
# 2  
Old 07-08-2009
"But it's returning "4479620" instead of "4479620"


What is the exact result you expecting?
# 3  
Old 07-08-2009
Suman,

Hope this helps:

echo $XML_PUB_REQUEST |awk -F '"' '{print $2}'

Quote:
Originally Posted by suman.g
Hi All,

Problem Description:
Code:
XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME" 
"CP_SHORT_NAME"`
echo Report Request: $XML_REP_REQUEST  --to print value in log file

While execution the value of 'XML_REP_REQUEST' is 'Prozess "4479620" für "CONCURRENT TEST_REPORT " gestartet Normal beendet'
I am storing the sub string '4479620' of variable XML_REP_REQUEST in variable 'XML_REP_REQUEST' using code below:
Code:
XML_PUB_REQUEST_ID=`echo $XML_PUB_REQUEST |tr -s " "| cut -d" " -f2|tr -d """`

But it's returning "4479620" instead of 4479620.

Any idea where I am going wrong Smilie

Many thanks,
Suman

---------- Post updated at 02:05 AM ---------- Previous update was at 01:38 AM ----------

topic changed...
# 4  
Old 07-08-2009
Hi,

I tried with 'echo $XML_PUB_REQUEST |awk -F '"' '{print $2}'' but it's giving error 'awk: can't open {print $2}'.

I got two solutions and it's working fine:
Code:
1-XML_PUB_REQUEST_ID=`echo $XML_PUB_REQUEST |tr -s " "|cut -d" " -f2|sed s/\"//g`
2-XML_PUB_REQUEST_ID=`echo $XML_PUB_REQUEST |tr -s " "| cut -d" " -f2|tr -d '"'`

Thanks,
Suman
# 5  
Old 07-08-2009
This work for me in KSH.

Can you create file /tmp/script.ksh
Put text below in this script. Run: chmod +x /tmp/script.ksh ; ./tmp/script.ksh

#!/bin/ksh
XML_PUB_REQUEST='Prozess "4479620" für "CONCURRENT TEST_REPORT " gestartet Normal beendet'
echo $XML_PUB_REQUEST |awk -F '"' '{print $2}'
# 6  
Old 07-09-2009
Hi,

I tried as mentioned below but it didn't work with
Code:
echo $XML_PUB_REQUEST |awk -F '"' '{print $2}'

After removing -F '"' from awk command it worked fine.
Code:
'echo $XML_PUB_REQUEST |awk '{print $2}'|tr -d '"'`

Many Thanks,
Suman
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Date substring from a string

Hi, I have 2 statements in a file a.sh start time is Fri Jan 9 17:17:33 CST 2015 a.sh end time is Fri Jan 9 17:47:33 CST 2015 I am required to get only the time out of it. like 17:17:33 & 17:47:33 PLs suggest (21 Replies)
Discussion started by: usrrenny
21 Replies

3. UNIX for Dummies Questions & Answers

get substring from string variable

Hi Dears, How to use variable in string location of expression ${string:index:length} to get substring from string? I encounter error "bad substitution" when I use expression ${$var:0:5} to get first 5 characters from $var. Could you please help me out of this? Thanks! (2 Replies)
Discussion started by: crest.boy
2 Replies

4. Shell Programming and Scripting

Replacing a string with its substring

Hi All, Below is some sample content of my input file: There are many types and traditions of anarchism, some of which are ]. Strains of anarchism have been divided into the categories of ] and ] or similar dual classifications. Anarchism is often considered to be a radical ] ideology, and... (8 Replies)
Discussion started by: satheeshkumar
8 Replies

5. Shell Programming and Scripting

substring and string position

Hi I want to use korn shell. I have files in a directory of following format abc01of09xyz abc02of09mno aabc03of09qrs --- -- requirement first is to check if any files of format "abc*of*" exists. If yes then match the number of such files with the number mentioned in each files(09 in... (1 Reply)
Discussion started by: subusona
1 Replies

6. Shell Programming and Scripting

Extracting substring from string

Hi awk and sed gurus, Please help me in the following. I have the following entries in the file ABCDErules AbHDPrules ABCrules -- -- and other entries in the file. Now, I want to extract from the file that contain entries for *rules and process it separately. How can i do it... (6 Replies)
Discussion started by: sdosanjh
6 Replies

7. Shell Programming and Scripting

Help with string and substring also I/O

#!/bin/sh PRINTF=/usr/bin/printf PASSWD=/etc/passwd $PRINTF "Enter a UserID\n" read USERID if ; then $PRINTF "$USERID does not exist, please contact IT service\n" exit 1 fi USERHOME=`grep "^$USERID:" $PASSWD | awk -F : '{print $6}'` USERSHELL=`grep "^$USERID:"... (1 Reply)
Discussion started by: ikeQ
1 Replies

8. UNIX for Dummies Questions & Answers

How to get the substring from the string

Hi All, Can anybody help me to get the substring from the given string. (3 Replies)
Discussion started by: Anshu
3 Replies

9. Shell Programming and Scripting

getting a substring from a string

hi all, I am trying to extract SUBSTRINGS out of a string using ksh. The string is "SAPR3K.FD0.FA.TJ.B0010.T050302" I tried using a= `expr substr $stringZ 1 2` which is giving me a syntax error, donno why?? any ideas why its not working?? I also tried echo "welcome" | awk '{... (3 Replies)
Discussion started by: maradona
3 Replies

10. Programming

can i get a substring from a string?

for example, the string a is "abcdefg", can i get a substring "bcd" (from ato a) from string a? thank you (4 Replies)
Discussion started by: dell9
4 Replies
Login or Register to Ask a Question