Visit The New, Modern Unix Linux Community


Substring in string with whitespaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substring in string with whitespaces
# 1  
Substring in string with whitespaces

hello,

i have this string:
variable="1234 /PARAMETER_1:text /PARAMETER_2Smiliethertext"

i tried to do
expr match $variable '.*\([TER_1:[a-z]*\)'

but i keep getting expr error

i need to extract the word text...

thank you
# 2  
one way:

Code:
#  echo "1234 /PARAMETER_1:text /PARAMETER_2thertext" | sed 's/.*TER_1:\([a-z]*\).*/\1/'
text

This User Gave Thanks to Tytalus For This Post:
# 3  
Thank you Tytalus!
# 4  
Quote:
Originally Posted by Aloush89
hello,

i have this string:
Code:
variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"

i tried to do
Code:
expr match $variable '.*\([TER_1:[a-z]*\)'

but i keep getting expr error

i need to extract the word text...

thank you
updated.
Code:
variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"
echo $variable |awk -F":| " '{print $3}'


Last edited by rdcwayx; 10-11-2010 at 02:08 PM..
# 5  
Quote:
Originally Posted by rdcwayx
Code:
variable="1234 /PARAMETER_1:text /PARAMETER_2:othertext"
echo $variable |awk -F "[ |:]" '{print $3}'

@rdcwayx

The "|" in the character class isn't use as an OR operator but as a fieldseparator:
Code:
awk -F"[ |:]"

The OR operator could be used like:
Code:
awk -F":| "

This User Gave Thanks to Franklin52 For This Post:

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #418
Difficulty: Easy
'JavaScript' is a trademark of Oracle Corporation in the United States.
True or False?

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

Construct Array from String seperated by different whitespaces

My string variable which gets the output from the result of a database query has values as below: line="2019-09-11 15:17:55 CR1234 anonymous Deployed DR_only Back_APP" I wish to construct an array (my_array) which should have entries as below. Note: 1. The first... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. 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

4. Shell Programming and Scripting

How to extract a substring from a string

Hi, I have an input string say for example: ABC,DEF,IJK,LMN,...,XYZ The above string is comma delimited. Now I have to extract the last part after the comma i.e. XYZ. :b: (3 Replies)
Discussion started by: bghosh
3 Replies

5. 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

6. Shell Programming and Scripting

get substring from string

Hi All, Problem Description: 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... (5 Replies)
Discussion started by: suman.g
5 Replies

7. Shell Programming and Scripting

To split a string to obtain the words delimited by whitespaces

Please can someone thow some light what is the best way to split a string to obtain the words delimited by whitespaces. (4 Replies)
Discussion started by: Sudhakar333
4 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

Featured Tech Videos