Solved Awk / Sed to delete anything before the match

December 19, 2011 at 08:25:49
Specs: Linux x86_64)
I am writing an html crawling script in order to quickly download data from a very huge and badly indexed site.

The website shows the link for the first and last page of the db's result whitch are like for the first page for the last page (where x stands for an unknown number)

i want to read the last page's link and cut off anything but that last number, then compose all the pages links terminating from 1 (whitch of course will be the first page) to x using a simple loop and a counter.

My problem is all about isolating that "x number" with a regex (awk or sed) both the number (be it 2, 3 or 4 digits long) and the link may differ from time to time in content and lenght.

I need to find a regex whitch recognizes the last number (not digit) there is in a line and isolate it.

I know it's kid's stuff... but i AM a kid.

Thank you in advance.

See More: Awk / Sed to delete anything before the match

Report •

December 19, 2011 at 09:08:00
✔ Best Answer
With this data structure, a way is to set the Field Seperator to "-". Then delete the string from the end of field 2:

echo ""|awk ' BEGIN { FS="-" }
print $2
} '

Let me know if you have any questions.

Report •

December 19, 2011 at 10:30:37
You're great.

In the meanwhile, i solved the problem "my way" by piping lots of sed commands together and trying with a thousand combinations until i got the numbers.

But your solution is great and i guess it's much bug proof than mine.

I've stumbled upon dozens of guides about manipulating text with bash tools but they're all too simple or too complicated for me. Could you point out a good, organized one for me if you know any? I'd appreciate it a lot.

And thank you for the code again.

Report •

December 19, 2011 at 11:18:22
Thank you for the kind words. I have to get you to talk to my boss and my girl friend. :)

Anyway ...

# my favorite sed link is Eric Pement's one liners:

# sed one liners explained

# favorite awk tutorial

# favorite bash tutorial by Mendel Cooper:

Report •

Related Solutions

December 19, 2011 at 11:47:53
It would be the least i can do. With this i will show MY boss i'm not only a "cheap teenager accountant" aha

And yes i hate accounting. With all my forces. Hanger makes will.

And thanks again for the links, you've just burnt all my holiday spare time. :D

Report •

Ask Question