LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2011, 05:58 PM   #1
rperezalejo
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Rep: Reputation: Disabled
search last character of many in a line


hello people, i have been doing some simple scripts for a while but i am facing a situation in witch i donīt have any idea so i request your help:

i have a file full of lines like these one:

http://localhost/repo/pool/main/a/apt/apt_0.7.20.2+lenny2_i386.deb[/url]

i would like to have only the last part "apt_0.7.20.2+lenny2_i386.deb" and then get only the name against a list of package name but that is simpler.

So for my quest iīve thought two possibilities:
1- finding the last "/" and print the last part
2- finding the fisrt "/" beginning from the end and print the last part

wait any help from you....hugs
 
Old 11-05-2011, 07:37 PM   #2
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
I don't know what "against a list of package name" means, but the regex you want for everything after the last / is [^/]*$
 
Old 11-05-2011, 08:01 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Code:
sed -n '/\/repo\//s#\[/url]##;s#.*/##p' packagelist >packages
grep -f packagenames bigpackagelist
Having to escape forward slashes make the regex expression look more complicated.
Lines with '/repo/' are selected. The ending '[/url]' is stripped. Then everything up to the last slash is removed.

The output is saved to the the file packages, which grep uses for the matching pattern list (-f option).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ character search in text file lindaonline15 Programming 1 06-23-2011 07:07 AM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-01-2010 11:45 PM
how to search and replace character from middle of line vishal_titre Linux - General 7 09-30-2008 02:46 AM
Search values within multiple files line to line Chrizzieej Programming 5 09-26-2008 04:11 PM
How to search for a character? mimf Linux - Newbie 1 12-03-2003 06:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration