Php/awk processing CSV

Source: Internet
Author: User

Take the 5th column, remove the opening closing quotation marks, and match the lines starting with HTTP//, https://, ftp://

* awk

Awk-f "," ' Str=gsub (/(^\ "*) | ( \ "*$)/," ", $ $) {if ($5~/(^http (s)?: \ \ /\/)| (^ftp:\/\/)/) print $} '   .. /data/t_video.csv >. /data/urls.csv

  

* PHP

<?php//awk-f "," ' Str=gsub (/(^\ "*) | ( \ "*$)/," ", $ $) {if ($5~/(^http (s)?: \ \ /\/)| (^ftp:\/\/)/) print $ "//... /data/t_video.csv >. /data/urls.csv$in = new Splfileobject ('.. /data/t_video.csv ', ' RB '), if (! $in) {    throw new Exception (' Open file for read failed! ');} $out = new Splfileobject ('.. /data/urls.csv ', ' W '), if (! $out) {    throw new Exception (' Open file for write failed! ');} $a = []; $videoURL = "; foreach ($in as $lineNum = = $line) {    $a = explode (', ', $line);    if (!isset ($a [4])) {        continue;    }    $videoURL = $a [4];    if (7<strlen ($videoURL)) {        $videoURL = Trim ($videoURL, "\" ");        if (Preg_match ('/^[http:\/\/|ftp:\/\/|https:\/\/]/', $videoURL)) {            $out->fwrite ($videoURL. php_eol);}}    

  

Input

.. /data/t_video.csv

"9", "Other", "ULTIMATE PHOTO Guide", NULL, "Http://118.190.209.209/media/mp4/1.mp4", "http://118.190.209.209/media/png/ 1.png "," ULTIMATE PHOTO Guide "" 10 "," other "," the VERGE ", NULL," Http://118.190.209.209/media/mp4/2.mp4 ","/HTTP/ 118.190.209.209/media/png/2.the_verge.png "," The Verge "" 11 "," Other "," Microsoft Power BI ", NULL," http://118.190.209.209 /media/mp4/3.mp4 "," Http://118.190.209.209/media/png/3.png "," Microsoft Power BI "

  

Output

.. /data/url.csv

Http://118.190.209.209/media/mp4/1.mp4http://118.190.209.209/media/mp4/2.mp4http://118.190.209.209/media/mp4/3.mp4

  

Php/awk processing CSV

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.