连接CSV文件,跳过第二行



我正在使用PowerShell连接社交媒体日志文件和Facebook,在他们无限的智慧中,在他们的标题行添加了第二行。

我现在使用这个:

Get-ChildItem -Filter *.csv | Select-Object -ExpandProperty FullName | Import-Csv | Export-Csv $FileOut -NoTypeInformation -Append

连接Twitter日志,效果很好。是否有一种"简单"的方法可以在连接期间跳过所有文件中的第二行?我知道我可以做一些数据工作之后从结果文件中删除第二行(因为它是静态的),但我宁愿看看我是否可以从一开始就摆脱它。

如果有人好奇,我可以分享前两行,但它特别长,令人讨厌=D

ETA:理想情况下,我要么需要弄清楚a)如何采取连接行,并让它知道头是两行长,然后我可以从结果文件中删除第二行或B)如何让连接过程跳过每个文件的第二行,而不需要大量的工作。

这是文件的前两行(所有真正相关的,因为第二行是我想跳过的):

"Post ID",Permalink,"Post Message",Type,Countries,Languages,Posted,"Audience Targeting","Lifetime Post Total Reach","Lifetime Post organic reach","Lifetime Post Paid Reach","Lifetime Post Total Impressions","Lifetime Post Organic Impressions","Lifetime Post Paid Impressions","Lifetime Engaged Users","Lifetime Matched Audience Targeting Consumers on Post","Lifetime Matched Audience Targeting Consumptions on Post","Lifetime Negative Feedback from Users","Lifetime Negative Feedback","Lifetime Post Impressions by people who have liked your Page","Lifetime Post reach by people who like your Page","Lifetime Post Paid Impressions by people who have liked your Page","Lifetime Paid reach of a post by people who like your Page","Lifetime People who have liked your Page and engaged with your post","Lifetime Organic views to 95%","Lifetime Organic views to 95%","Lifetime Paid views to 95%","Lifetime Paid views to 95%","Lifetime Organic Video Views","Lifetime Organic Video Views","Lifetime Paid Video Views","Lifetime Paid Video Views","Lifetime Average time video viewed","Lifetime Video length","Lifetime Post Stories by action type - like","Lifetime Post Stories by action type - share","Lifetime Post Stories by action type - comment"
,,,,,,,,"Lifetime: The number of people who had your Page's post enter their screen. Posts include statuses, photos, links, videos and more. (Unique Users)","Lifetime: The number of people who had your Page's post enter their screen through unpaid distribution. (Unique Users)","Lifetime: The number of people who had your Page's post enter their screen through paid distribution such as an ad. (Unique Users)","Lifetime: The number of times your Page's post entered a person's screen. Posts include statuses, photos, links, videos and more. (Total Count)","Lifetime: The number of times your Page's posts entered a person's screen through unpaid distribution. (Total Count)","Lifetime: The number of times your Page's post entered a person's screen through paid distribution such as an ad. (Total Count)","Lifetime: The number of unique people who engaged in certain ways with your Page post, for example by commenting on, liking, sharing, or clicking upon particular elements of the post. (Unique Users)","Lifetime: The number of people who matched the audience targeting that clicked anywhere in your post on News Feed. (Unique Users)","Lifetime: The number of clicks anywhere in your post on News Feed from the user that matched the audience targeting on it. (Total Count)","Lifetime: The number of people who have given negative feedback to your post. (Unique Users)","Lifetime: The number of times people have given negative feedback to your post. (Total Count)","Lifetime: The number of impressions of your Page post to people who have liked your Page. (Total Count)","Lifetime: The number of people who saw your Page post because they've liked your Page (Unique Users)","Lifetime: The number of paid impressions of your Page post to people who have liked your Page. (Total Count)","Lifetime: The number of people who like your Page and who saw your Page post in an ad or sponsored story. (Unique Users)","Lifetime: The number of people who have liked your Page and clicked anywhere in your posts. (Unique Users)","Lifetime: Number of times your video was viewed to 95% of its length without any paid promotion. (Unique Users)","Lifetime: Number of times your video was viewed to 95% of its length without any paid promotion. (Total Count)","Lifetime: Number of times your video was viewed to 95% of its length after paid promotion. (Unique Users)","Lifetime: Number of times your video was viewed to 95% of its length after paid promotion. (Total Count)","Lifetime: Number of times your video was viewed for more than 3 seconds without any paid promotion. (Unique Users)","Lifetime: Number of times your video was viewed for more than 3 seconds without any paid promotion. (Total Count)","Lifetime: Number of times your video was viewed more than 3 seconds after paid promotion. (Unique Users)","Lifetime: Number of times your video was viewed more than 3 seconds after paid promotion. (Total Count)","Lifetime: Average time video viewed (Total Count)","Lifetime: Length of a video post (Total Count)","Lifetime: The number of stories created about your Page post, by action type. (Total Count)",,

对于5.1,可以从arraylist中删除特定的索引。该方法不输出到管道,所以它需要一个循环:

foreach ($file in (Get-ChildItem -Filter *.csv).FullName) {
$csv = [System.Collections.ArrayList](Import-Csv $file)
$csv.RemoveAt(1)
$csv | Export-Csv $FileOut -NoTypeInformation -Append
}

-Skip/-SkipIndex应该工作得很好,然而Facebook,在他们无限的智慧中,已经决定使第一行中的项目不是唯一的,所以我将不得不不走简单的路线,只是删除第二行,而不是删除前两行,并添加我自己的标题,这样我就可以在一切完成后使用数据。

最新更新