Get portion of string from the end


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get portion of string from the end
# 1  
Old 08-28-2015
Get portion of string from the end

Hi all,

Can anyone suggest a way to get a portion of string from the end?

So:

Code:
$ORACLE_SID=blt10cr1

We can drop the final '1' and end up with:

Code:
$ORACLE_SID=blt10cr

So far I have the following:

Code:
echo $ORACLE_SID | cut -c1-5

and
Code:
echo $ORACLE_SID |  cut -c1-6 | rev

any ideas?

Thanks in advance.

jd
# 2  
Old 08-28-2015
Code:
$ echo $ORACLE_SID | sed 's/.$//'
blt10cr


Last edited by vbe; 08-28-2015 at 10:01 AM..
# 3  
Old 08-28-2015
If its bash:
Code:
echo "${ORACLE_SID:0:${#ORACLE_SID}-1}"

hth
# 4  
Old 08-28-2015
Try also
Code:
echo "${ORACLE_SID%?}"
blt10cr

# 5  
Old 08-28-2015
thank guys that works.
Code:
echo "${ORACLE_SID%?}"
blt10cr

nice and simple :-)

Last edited by vbe; 08-28-2015 at 10:02 AM.. Reason: remember to use code tags next time thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

2. Shell Programming and Scripting

Terminate left side portion of a string

I have a awk file which consists of the follwoing code in file select.awk : /xxx/ { time = gensub(/xxx \*\*\*(.*)/, "\\1", "g") printf("%s\n",time) next } and an input file with the following file file.txt :- xxx ***Wed May 2 18:00:00 CDT 2012 AAA AAAA AAAA xxx... (4 Replies)
Discussion started by: shikshavarma
4 Replies

3. Shell Programming and Scripting

How to extract portion of a string?

Hi Gurus, Would like to seek some help on how to extract a portion of string from log's output as shown below. Sample of raw data: piece handle=/test123/disk_dump/test123/df0_cntrl_PCPFCI20120404_68498 tag=TAG20120404T180035 comment=NONE piece... (13 Replies)
Discussion started by: superHonda123
13 Replies

4. Shell Programming and Scripting

Remove first portion of string

I have a script which currently uses a file containing a list of directories as an argument. The file is read in to an array, and then the array is iterated in a for loop. What I would like to do is cut off the first few directories of the directory path (they won't exist on the server where the... (5 Replies)
Discussion started by: msarro
5 Replies

5. Shell Programming and Scripting

Extracting a portion of the string and comparing

I have 2 text files say file1.txt and file2.txt . Some of the sample records for file1.txt were shown below: XXXXX12345XXXXXXX12 3456789YYYYY XXXXXXXXXX12345XX123457485YYYYY XX12345XXXXXXXXXX123454658YYYYY for file2.txt, some of the sample records were shown below: ... (5 Replies)
Discussion started by: bobby1015
5 Replies

6. Shell Programming and Scripting

Help on extracting portion of string

Hi Gurus, I've some sample of my log information as shown below. -> Processing ABCD123456 This is tp version 372.04.57 (release 700, unicode enabled) This is R3trans version 6.14 (release 700 - 05.03.09 - 08:28:00). unicode enabled version R3trans finished (0000). Warning: Parameter... (1 Reply)
Discussion started by: superHonda123
1 Replies

7. Shell Programming and Scripting

extract string portion from filename using sed

Hi All, I posted something similar before but I now have a another problem. I have filenames as below TOP_TABIN240_20090323.200903231830 TOP_TABIN235_1_20090323.200903231830 i need to extract the dates as in bold. Using bash v 3.xx Im trying to using the print sed command but... (11 Replies)
Discussion started by: santam
11 Replies

8. Shell Programming and Scripting

extract string portion using sed

Hi All I have 3 files as listed below and highlighted in bold the portions of the filenames I need to extract: TOS_TABIN218_20090323.200903231830 TOS_TABIN219_1_20090323.200903231830 TOS_TABIN219_2_20090323.200903231830 I tried source_tabin_name=`echo $fname | sed 's/_.*//'` but I... (6 Replies)
Discussion started by: santam
6 Replies

9. UNIX for Dummies Questions & Answers

Stripping a portion of string from behind!!!

Hi, How to strip a portion of a file name from behind...Say for Eg..i have a file name like aaaaa.bbbbb.Mar-17-2007 i want to remove .Mar-17-2007...is there a one line command which can give this output... Thanks Kumar (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies

10. UNIX for Dummies Questions & Answers

How to extract a portion of a string from the whole string

How to extract a portion of a string from a full string using unix. For example: Say source string is = "req92374923.log" I want only the numeric portion of the string say "92374923" how to do that in Unix. (2 Replies)
Discussion started by: ds_sastry
2 Replies
Login or Register to Ask a Question