Sponsored Content
Top Forums Shell Programming and Scripting Extracting substring from variable Post 302973534 by shamrock on Wednesday 18th of May 2016 11:17:53 AM
Old 05-18-2016
The one below should work irrespective of shell version...
Code:
export var="DR"
echo ${var%"${var#[A-Z]}"}
D

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

2. Shell Programming and Scripting

extracting substring from a file name

hi i need to name a file with a substring of a another file name. i.e. if the old filename is abc.txt , the new filename should be abc_1.txt i should get the substring of the file name and then name the new one please let me know how to do it (4 Replies)
Discussion started by: adityamahi
4 Replies

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

4. Shell Programming and Scripting

Extracting a substring from a string in unix

Hi, I would like to extract a substring from a string in unix. eg: ./checkfile.sh -- i need only checkfile.sh from this string. Could someone help me out in this... Regards Arun (19 Replies)
Discussion started by: arunkumarmc
19 Replies

5. Shell Programming and Scripting

Extracting substring

Hi, I have string in variable like '/u/dolfin/in/DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010' and i want to conevrt this string into only "DOLFIN.PRL_100.OIB.TLU.001.D20110520.T040010" (i.e file name). Is there any command to extracting string in some part ?(rather than whole path)? ... (5 Replies)
Discussion started by: shyamu544
5 Replies

6. UNIX for Dummies Questions & Answers

Extracting substring between pattern only one time

Hello ifconfig return : eth0 Link encap:Ethernet HWaddr 11:24:1D:C1:99:BA inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:37307 errors:0 dropped:0 overruns:0 frame:0 ... (2 Replies)
Discussion started by: jcdole
2 Replies

7. Shell Programming and Scripting

Need help in extracting the substring in UNIX

Hi all, I need to extract the "abcdef" from the below string Digital_abcdef_20130103.txt.gz The length of the "abcdef" will be changing but it will be always after the word Digital_ and before the second underscore help in this regard is highly appreciated (3 Replies)
Discussion started by: rithushri
3 Replies

8. Shell Programming and Scripting

Help on extracting a substring from the input string

Hi, I am new to Unix. I am trying to extract a substring from an input string: Ex - input string: deploy_v11_9_1 i want to extract and store the value v11_9_1 from the input string in a new variable. I am using following command in my shell script file: echo "Enter the folder name u... (5 Replies)
Discussion started by: Pranav Bhasker
5 Replies

9. Shell Programming and Scripting

Bash - Extracting whole word containing substring

hello. I get this text when using some command : S | Name | Type | Version | Arch | Repository --+-----------------+---------+---------+------+------------- | AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local I need to get "AdobeReader_enu" from the the pattern "Ado"... (7 Replies)
Discussion started by: jcdole
7 Replies

10. Shell Programming and Scripting

Extracting a substring from Line

Hi All I have a line which is as below 1234567 Gagan Paswani zz23432 1000000000 1000000000 ASTHEYXX-RTUC zz23432 I need to extract the first occurence of zz23432 which will have the reg expression as {2}{5} Could you please assist as to how I can extract this... (3 Replies)
Discussion started by: Prashantckc
3 Replies
strfind(3GEN)					     String Pattern-Matching Library Functions					     strfind(3GEN)

NAME
strfind, strrspn, strtrns, str - string manipulations SYNOPSIS
cc [ flag ... ] file ... -lgen [ library ... ] #include <libgen.h> int strfind(const char *as1, const char *as2); char *strrspn(const char *string, const char *tc); char * strtrns(const char *string, const char *old, const char *new, char *result); DESCRIPTION
The strfind() function returns the offset of the first occurrence of the second string, as2, if it is a substring of string as1. If the second string is not a substring of the first string strfind() returns -1. The strrspn() function trims chartacters from a string. It searches from the end of string for the first character that is not contained in tc. If such a character is found, strrspn() returns a pointer to the next character; otherwise, it returns a pointer to string. The strtrns() function transforms string and copies it into result. Any character that appears in old is replaced with the character in the same position in new. The new result is returned. USAGE
When compiling multithreaded applications, the _REENTRANT flag must be defined on the compile line. This flag should only be used in mul- tithreaded applications. EXAMPLES
Example 1: An example of the strfind() function. /* find offset to substring "hello" within as1 */ i = strfind(as1, "hello"); /* trim junk from end of string */ s2 = strrspn(s1, "*?#$%"); *s2 = ''; /* transform lower case to upper case */ a1[] = "abcdefghijklmnopqrstuvwxyz"; a2[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; s2 = strtrns(s1, a1, a2, s2); ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
string(3C), attributes(5) SunOS 5.10 20 Jan 1999 strfind(3GEN)
All times are GMT -4. The time now is 12:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy