'I have written a sed script and want to include a command that will pull a long string of numbers, all being 0-9, and could possibly have letters
I have a non-pixelized pdf that I have converted into a .tdt. I am trying to pull some specific information from it to put into a table in html. I am wanting to pull the "name", which is followed by spaces and then the number I want to capture. There are two other names with space in between that precede the name I want to capture. The number could look like this, 125000009856472333 or 125LLLLLVI4673302 or 125689*990000. I have written these two lines:
s="$s; s/^.*(Name) +(*.)$/\2/p" |sed -rn "$s" input.files.txt
and
s="$s; s/^.* +*.(Name) +*(0-9a-zA-z)$/\2/p" |sed -rn "$s" input.files.txt
I receive nothing
s="$s; s/^Name *([^)]+)/Name\t([^)]+)/p" |sed -rn "$s" input.files.txt
output was**:** Name ([^)]+) instead of Invoice Number and the number we want to capture.
I am wanting to use this to process 21 files that I have concatenated. The result should be two columns, one with name and the other column with different combinations of letters, numbers and possibly some special characters.
Solution 1:[1]
Without a minimal, reproducible example and/or more details I can't be sure, but to capture the Name and the numbers/letters after the whitespace perhaps you want something like:
sed -n 's/.*\(Name\)[[:space:]]\{1,\}\([[:alnum:]]\{1,\}\)/\1\t\2/p' file
You can also add special characters to [[:alnum:]] if you need to, e.g. [[:alnum:]+-,.], or change [[:alnum:]] to [[:alnum:][:punct:]] if you want to capture all printable characters except space.
Does that answer your question?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jared_mamrot |
