how to extract data between first and 2nd last delimiter.

faizal Izham

New Member
Joined
Oct 26, 2017
Messages
7
Hi All,

I would like to know if there is an excel formula to extract data in the middle between first and 2nd last delimiter.
I have a sample data as below.

device_hostname1_rootvg_lun1_1_vol
device_hostname1_vgDBapp_lun397_1_vol
device_hostname1_vgDBbkp_lun398_1_vol
device_hostname1_vgDButils_lun399_1_vol
device_hostname1_2_Arch1_SharedLUN01_lun400_1_vol
device_hostname1_2_Arch1_SharedLUN02_lun401_1_vol
device_hostname1_2_Arch1_SharedLUN03_lun402_1_vol

and i wanted to have a formula which can output the data as per below.

hostname1_rootvg_lun1
hostname1_vgDBapp_lun397
hostname1_vgDBbkp_lun398
hostname1_vgDButils_lun399
hostname1_2_Arch1_SharedLUN01_lun400
hostname1_2_Arch1_SharedLUN02_lun401
hostname1_2_Arch1_SharedLUN03_lun402

Thank You in advance.

Faizal







<tbody>
</tbody>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello,

It seems to me the very step is to use a formula which counts the total number of delimiters ...

Do you already use such a formula ...???
 
Upvote 0
Re,

A formula to be tested :

Code:
=LEFT(A1,IFERROR(FIND(CHAR(1),SUBSTITUTE(A1,"_",CHAR(1),LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-2)),"")-1)
 
Upvote 0
Hi James006,

Thanks for your code.. however the code only return as follow.

device_hostname1_rootvg_lun1
device_hostname1_vgDBapp_lun397
device_hostname1_vgDBbkp_lun398
device_hostname1_vgDButils_lun399
device_hostname1_2_Arch1_SharedLUN01
device_hostname1_2_Arch1_SharedLUN02
device_hostname1_2_Arch1_SharedLUN03

I would need to remove "device_" as well from the output. I'm still a beginner in excel.. so far i only googled for what i had wanted and not entirely understand what each formula does.
Appreciate your help on this matter

Thank You.

Faizal
 
Upvote 0
Hi,

To remove device_ ... you can use following

Code:
=SUBSTITUTE(LEFT(A18,IFERROR(FIND(CHAR(1),SUBSTITUTE(A18,"_",CHAR(1),LEN(A18)-LEN(SUBSTITUTE(A18,"_",""))-2)),"")-1),"device_","")

HTH
 
Upvote 0
Hi James006,

Thank you.. your code works perfectly.... also manage to find a stupid way of doing things as well by modifying a bit of your code..

=MID(LEFT(C2,IFERROR(FIND(CHAR(1),SUBSTITUTE(C2,"_",CHAR(1),LEN(C2)-LEN(SUBSTITUTE(C2,"_",""))-1)),"")-1),FIND("_",LEFT(C2,IFERROR(FIND(CHAR(1),SUBSTITUTE(C2,"_",CHAR(1),LEN(C2)-LEN(SUBSTITUTE(C2,"_",""))-1)),"")-1))+1,256)
but this one works perfectly

=SUBSTITUTE(LEFT(A18,IFERROR(FIND(CHAR(1),SUBSTITUTE(A18,"_",CHAR(1),LEN(A18)-LEN(SUBSTITUTE(A18,"_",""))-1)),"")-1),"device_","")
Much appreciated and Thank You.

Faizal.
 
Upvote 0
This should work:

=MID(LEFT(A1,FIND("|",SUBSTITUTE(A1,"_","|",LEN(A1)-LEN(SUBSTITUTE(A1,"_",""))-1))-1),FIND("_",A1)+1,LEN(A1))
 
Upvote 0
Glad you could fix your problem ...

Thanks for your Thanks ...
 
Upvote 0
In fact, if your sample data is fully representative, then all you would need is this.

Excel Workbook
AB
1device_hostname1_rootvg_lun1_1_volhostname1_rootvg_lun1
2device_hostname1_vgDBapp_lun397_1_volhostname1_vgDBapp_lun397
3device_hostname1_vgDBbkp_lun398_1_volhostname1_vgDBbkp_lun398
4device_hostname1_vgDButils_lun399_1_volhostname1_vgDButils_lun399
5device_hostname1_2_Arch1_SharedLUN01_lun400_1_volhostname1_2_Arch1_SharedLUN01_lun400
6device_hostname1_2_Arch1_SharedLUN02_lun401_1_volhostname1_2_Arch1_SharedLUN02_lun401
7device_hostname1_2_Arch1_SharedLUN03_lun402_1_volhostname1_2_Arch1_SharedLUN03_lun402
Extract text
 
Upvote 0
Thank You Peter and Steve for posting alternative code to get things done.. Appreciate your help very much..

Kudos to all who have helped..


Faizal
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,255
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top