How to get only some line information from text

here the text file example i want to grab only the line head with "lsb.ibm.kbank"

dadadadadadadadadadadadadad hahahahah stupid me stupid me stupid me stupid me
lsb.ibm.kbank:FinCheck:050112:AIX:6.3.2:fhgt.dll:dserver1:198.168.65.108:C:F:FC SCSI:user1
lsb.ibm.kbank:FinCheck:050112:AIX:7.3.1:aserver1:fhgt.dll:178.168.65.188:C:F:FC SCSI:user3
hahahahahahahah crazy crazy no skill i'm suck toobad lksdjflskdhfsdkfj bla bla bla
dadadadadadadadadadadadadad hahahahah stupid me stupid me stupid me stupid me
lsb.ibm.kbank:FinCheck:050112:AIX:7.3.2:fhgt.dll:dserver1:178.168.65.118:C:F:FC SCSI:admin
lsb.ibm.kbank:FinCheck:050112:AIX:6.3.0:fhgt.dll:dserver1:178.168.65.108:C:F:FC SCSI:user2
hahahahahahahah crazy crazy no skill i'm suck toobad lksdjflskdhfsdkfj bla bla bla
dadadadadadadadadadadadadad hahahahah stupid me stupid me stupid me stupid me
lsb.ibm.tbank:NoCheck:050112:AIX:5.3.0:fhgt.dll:dserver1:198.168.65.108:C:F:FC SCSI:user1
lsb.ibm.kbank:FinCheck:050112:AIX:6.3.1:fhgt.dll:dserver1:178.168.65.198:C:F:FC SCSI:Admin
dadadadadadadadadadadadadad hahahahah stupid me stupid me stupid me stupid me
dadadadadadadadadadadadadad hahahahah stupid me stupid me stupid me stupid me

[lsb.ibm.tbank]*:[NoCheck]*:120312:[AIX]*:[5.3.0]*:txgh.dll:[dserver1]*:[198.168.65.108]*:C:F:FC SCSI:[user1]*

and in each line i want only some part of the information

what function should i use to search and extract it into table

thank you

Almir's picture

How to get only some line information from text

Import text file into Excel as delimited file. You will get each row of data in separate cell. Filter rows with "lsb.ibm.kbank". Use SEARCH function to find starting character that you wish. Finally, use MID function with that starting character as an argument to extract part of a cell. You can also nest functions (SEARCH within MID). If you provide me searched string and length of text, I can extract it for you.

here my current work that i try to study

i'm newbie. i have to study and edit from other person code

example text file you can use above information line that i post

thank you a lot
--------------------------------------------------

Option Explicit

Sub TestImport()
Call ImportTextFile(Sheet2.Range("B1") & "\" & Sheet2.Range("B2") & ".txt", ":", Sheet2.Range("A4"))
End Sub

Public Sub ImportTextFile(strFileName As String, strSeparator As String, rngTgt As Range)
Dim lngTgtRow As Long
Dim lngTgtCol As Long
Dim varTemp As Variant
Dim strWholeLine As String
Dim intPos As Integer
Dim intNextPos As Integer
Dim intTgtColIndex As Integer
Dim wks As Worksheet

Set wks = rngTgt.Parent

intTgtColIndex = rngTgt.Column
lngTgtRow = rngTgt.Row

Open strFileName For Input Access Read As #1

While Not EOF(1)
Line Input #1, strWholeLine
If Right(strWholeLine, 1) <> strSeparator Then
strWholeLine = strWholeLine & strSeparator
End If
lngTgtCol = intTgtColIndex
intPos = 1
intNextPos = InStr(intPos, strWholeLine, strSeparator)
While intNextPos >= 1
varTemp = Mid(strWholeLine, intPos, intNextPos - intPos)
Cells(lngTgtRow, lngTgtCol).Value = varTemp
intPos = intNextPos + 1
lngTgtCol = lngTgtCol + 1
intNextPos = InStr(intPos, strWholeLine, strSeparator)
Wend
lngTgtRow = lngTgtRow + 1
Wend

Close #1
Set wks = Nothing
End Sub

Almir's picture

here my current work that i try to study

It looks as a code for import text file into Excel. I can not see (?) string that you are looking for. It is easy to import text as rows into Excel and find rows containing some string. What string are you looking for and what text do you want to extract starting from that string?

i Looking for Line That Start

i Looking for Line That Start With

"lsb.ibm.kbank"

[lsb.ibm.tbank]*:[NoCheck]*:120312:[AIX]*:[5.3.0]*:txgh.dll:[dserver1]*:[198.168.65.108]*:C:F:FC SCSI:[user1]*

and result should get only section that I mark it so it will left this to show on table

lsb.ibm.kbank:FinCheck:AIX:6.3.2:dserver1:198.168.65.108:user1

sorry for my bad english

thx you for ur concern I got

thx you for ur concern
I got it now as You said use MID to search it

vut i still have problem on choose only some part line

Almir's picture

thx you for ur concern I got

If you know exactly number of character to the right, you can get it by using MID function. If you don't, you can cut-off the part of cell after - let's say - "user1". If you don't need anything from a cell after "user1", use CTRL+H (Replace), like this: user1* replace with blank.