GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   bash regex or sed help (https://gfy.com/showthread.php?t=1067162)

fris 05-05-2012 09:28 AM

bash regex or sed help
 
never done regex in bash before, what im bascially trying to do is this perl/php regex

/(\d+)_\d+_\d+[_a-z]*\.jpg/i

what is gets is the facebook profile id, from a facebook image.

http://a1.sphotos.ak.fbcdn.net/hphot...20 4038_n.jpg

would get 80329313253

in php

preg_match('/(\d+)_\d+_\d+[_a-z]*\.jpg/i',$url,$matches);

match[1] would be the fb id

fris 05-05-2012 09:45 AM

actually figured out doing command substituion

Code:

#!/bin/bash

function profile() {
        d=${1#*_};
        d=${d#*_};
        d=${d%_*};
        d=${d%_*};
        echo ${d%_*};
}

profile http://a1.sphotos.ak.fbcdn.net/hphotos-ak-ash3/p480x480/558586_10150802565778254_80329313253_9861803_956204038_n.jpg


Barry-xlovecam 05-05-2012 09:45 AM

Code:

sed -i 's/x/y/g'
not /i

fris 05-09-2012 06:11 AM

Quote:

Originally Posted by Barry-xlovecam (Post 18931226)
Code:

sed -i 's/x/y/g'
not /i

got it with sed

Quote:

[fris@fris ~]$ echo "http://a1.sphotos.ak.fbcdn.net/hphotos-ak-ash3/p480x480/558586_10150802565778254_80329313253_9861803_95620 4038_n.jpg" | sed 's/.*_\([0-9]*\)_[0-9]*_[0-9]*_n\.jpg$/\1/'
80329313253
[fris@fris ~]$


All times are GMT -7. The time now is 05:07 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc