bash regex or sed help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55682

    #1

    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...56204038_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
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55682

    #2
    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
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • Barry-xlovecam
      It's 42
      • Jun 2010
      • 18083

      #3
      Code:
      sed -i 's/x/y/g'
      not /i

      Comment

      • fris
        Too lazy to set a custom title
        • Aug 2002
        • 55682

        #4
        Originally posted by Barry-xlovecam
        Code:
        sed -i 's/x/y/g'
        not /i
        got it with sed

        [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 ~]$
        Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

        Comment

        Working...