【发布时间】:2021-11-05 13:43:28
【问题描述】:
我正在使用 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)",,
【问题讨论】:
-
请分享您正在导入的示例 csv。
-
如果你想跳过一些行,你可以使用
Select-Object -Skip [int]... 在 PowerShell 版本 7+ 中你甚至可以使用Select-Object -SkipIndex 2,4,5或类似的东西 -
请分享一些示例数据,甚至可能是一些所需的输出数据(请以原始格式格式化为代码)
-
这似乎不是有效的 CSV。如果它只是您想要删除的文件的第二行,为什么不使用 PowerShell 版本 7 和
Select-Object的-SkipIndex参数? -
因为我在尝试导入时遇到错误。 ;-)
The member "Lifetime Organic views to 95%" is already present.
标签: powershell csv text-manipulation