regex - Regular expression help - what's wrong? -
I want to ask for help with my regex. I need to remove the very last part from each URL. I have marked it as 'to_extract' in the example below.
I want to know what is in the following reggeks when used with sed:
sed 's / ^ [ht | f] tp Sample content of file.txt * // 'file.txt
http: // a / b / c / to_extract ftp: // a / b / c / to_extract ... I'm getting the right result for FTP link but not for the HT. Thanks in advance for your explanation on this I
change [ht | F] to (ht | f) , will result in better results. [abc] means "a letter which is a , b or c ". [ht | F] means "a letter which is h , T , | or f ", Not exactly what you want. On some versions of sed, you have to call it from the -r option so that extended regags can be used: sed - R 's / ^ (ht | f) tp * \ /// 'file.txt If you want to remove the last part of the URL and do not want anything else, then you probably want
< Code> Sed -rn 's / ^ (ht | f) tp * \ / /// p 'file.txt
Comments
Post a Comment