Output to a single line

I have a .csv file that contain a list of urls. I want to write out a .csv file with just one line with a ‘|’ separator between urls.
from the .csv file:
https://www.abc.com/1206/FAQs
https://www.abc.com/1200/Links
https://www.abc.com/1201/Payment-Information
to a new .csv
/1206/FAQs|/1200/Links|/1201/Payment-Information

I tried a few things but each line comes out on a new line.
Here is the code:

$csv = (Import-Csv H:\GoogleAnalytics\MyURLS.csv -Header "Page")
foreach($row in $csv)
{ 
  $row.Page = $row.Page + "|" -replace 'https://www.abc.com'
  $row
}

Thanks in advance
Tom

Since you did not share your actual input CSV I assumed something … that’s actually all you need … if I got it right … :wink:

$CSVInput = @'
Page
https://www.abc.com/1206/FAQs
https://www.abc.com/1200/Links
https://www.abc.com/1201/Payment-Information
'@ |
    ConvertFrom-Csv

$CSVInput.Page -join '|'

Does you CSV file have only one column?

yes the .cvs file has only 1 column. Column name is “Page”.

Hmmm … when you specify the header in your import command it looks like the CSV file does not have a header. So you could treat it like a plain text file as well.

Did you try my code suggestion? Did it work?

Yes I tried your code and it did write out a single line.
I do need to drop the beginning part of the url https://www.abc.com
also would I write it out to a .csv file?
I need to take the one line and enter into another program.
I appreciate your help.

I assume that part worked with your code, didn’t it? :wink:

Now you just ahve to combine the output you’ve got from your code with the way to join the parts I showed in my code and you’re done.

That actually does not make any sense.

That’s quite vague. Can this other program take command line input? Will it read from an input file? …

It would be easier if you shared complete information.

BTW: When you share sample data or console output you should format it as code as well. This way we are able to copy and play around with it to reproduce your task. :wink:

Thanks for your help and your last note to format sample data and console output in code format.
I don’t work with Powershell too often. I appreciate your help and the Powershell community.

I have 56 separate .csv files that contain department URLS. The intent of this script is to eliminate me from enter the urls separately into a Google Analytics report for report filtering. The filtering text box wants a string of urls separated by the “|” character. So with your solution I can create 56 outputs that I can copy and paste into the filter’s text box… There is no API interface to feed them automatically into GA.

I see. :+1:t4:

So, I’m glad I could help. :slightly_smiling_face:

I want to add onto your solution to have the script go to the folder where I have 56 separate .csv files are located, loop through each .csv file and automatically create 56 separate output files with their one url string. This would save time from running your solution 56 times. The output file name would be the .csv’s filename… example OutputPlanningURLS.txt (the output format can be a .txt)

You should learn the very basics and core concepts anyway. Otherwise you will have problems understanding the help you get in forums like this. :wink:

With

You can list all desired files in a specified folder.

Then you can pipe this to

and run whatever steps you need to do for each individual file.

Please always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them.

Thank you Olaf! duly noted about learning the basics and core concepts. Thanks again for help again!