Hello,<\/p>\n
I am looking to see if someone can help me create a script to extract sequential numbers with 8 or more digits from a text file.<\/p>\n
I work in data quality and multiple times per week I have to do this manually.<\/p>\n
Here is an example of what I am working with:<\/p>\n
There are 4 lines of text for each number that I need to extract.<\/p>\n
“First set of words and numbers”<\/p>\n
“Second set of words and numbers”<\/p>\n
“Third set”<\/p>\n
“Fourth set - #11111111<\/span>”<\/p>\n I need to extract the number after the “hashtag” for each set and then put them sequentially like:<\/p>\n 11111111 Once they are listed sequentially I can copy them and put them in our work program. Essentially, I would like to just automate the process of getting those numbers every time I have to. Ideally, I would want something that I can copy and paste the lines of text into, it would extract and list those numbers, and then I could copy the numbers and paste them back into our program.<\/p>\n Anything to save the time it takes to remove everything before the 8 digit number manually would be helpful. Thank you in advance. I didn’t see anything that looked like it could help this specific situation in the previously answered topics of similar nature.<\/p>","upvoteCount":2,"answerCount":10,"datePublished":"2021-02-25T16:17:55.000Z","author":{"@type":"Person","name":"gubber12","url":"https://community.spiceworks.com/u/gubber12"},"acceptedAnswer":{"@type":"Answer","text":" if the format is always consistent you can do it even easier<\/p>\n basically get all the lines that have a pound (#) in it and then just take what’s after the pound symbol<\/p>\n many ways to ‘skin the meow meow’<\/p>","upvoteCount":1,"datePublished":"2021-02-25T18:44:07.000Z","url":"https://community.spiceworks.com/t/script-to-extract-sequential-numbers-in-a-txt-file/791958/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":" Hello,<\/p>\n I am looking to see if someone can help me create a script to extract sequential numbers with 8 or more digits from a text file.<\/p>\n I work in data quality and multiple times per week I have to do this manually.<\/p>\n Here is an example of what I am working with:<\/p>\n There are 4 lines of text for each number that I need to extract.<\/p>\n “First set of words and numbers”<\/p>\n “Second set of words and numbers”<\/p>\n “Third set”<\/p>\n “Fourth set - #11111111<\/span>”<\/p>\n I need to extract the number after the “hashtag” for each set and then put them sequentially like:<\/p>\n 11111111 Once they are listed sequentially I can copy them and put them in our work program. Essentially, I would like to just automate the process of getting those numbers every time I have to. Ideally, I would want something that I can copy and paste the lines of text into, it would extract and list those numbers, and then I could copy the numbers and paste them back into our program.<\/p>\n Anything to save the time it takes to remove everything before the 8 digit number manually would be helpful. Thank you in advance. I didn’t see anything that looked like it could help this specific situation in the previously answered topics of similar nature.<\/p>","upvoteCount":2,"datePublished":"2021-02-25T16:17:55.000Z","url":"https://community.spiceworks.com/t/script-to-extract-sequential-numbers-in-a-txt-file/791958/1","author":{"@type":"Person","name":"gubber12","url":"https://community.spiceworks.com/u/gubber12"}},{"@type":"Answer","text":" Do you need only the numbers? Does the text matter at all? Can you post a sanitized sample of the text file?<\/p>\n EDIT: typo<\/p>","upvoteCount":1,"datePublished":"2021-02-25T17:41:55.000Z","url":"https://community.spiceworks.com/t/script-to-extract-sequential-numbers-in-a-txt-file/791958/2","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":" Welcome<\/p>\n
\n11111112<\/p>\n$data = get-content \".\\sampler.txt\"\n$data -match \"#\" | \nforeach-object{($_ -split \"#\")[1]}\n<\/code><\/pre>\n
\n11111112<\/p>\n