0

I have data in a one column in a CSV file that looks like this:

backup:x:34:34:backup:/var/backups:/usr/sbin/nologin

I want to split it into multiple columns, splitting each value using colon symbol(:) delimiter and add customize headers. Output should look like this:

USERNAME   X   UID   GID   DESCRIPTION  HOMEDIR      SHELL 
----------
backup     x   34    34    backup      /var/backups  /usr/sbin/nologin

Thank you in advance.

1
  • Import-CSV cmdlet supports custom headers and delimiters. Commented Oct 29, 2021 at 10:14

1 Answer 1

4

The string value backup:x:34:34:backup:/var/backups:/usr/sbin/nologin can itself be thought of as a CSV record with : as delimiters, so you can use ConvertFrom-Csv:

PS ~> $string = 'backup:x:34:34:backup:/var/backups:/usr/sbin/nologin'
PS ~> $string |ConvertFrom-Csv -Delimiter ':' -Header USERNAME,X,UID,GID,DESCRIPTION,HOMEDIR,SHELL |Format-Table

USERNAME X UID GID DESCRIPTION HOMEDIR      SHELL
-------- - --- --- ----------- -------      -----
backup   x 34  34  backup      /var/backups /usr/sbin/nologin
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this @mathias. But upon opening the csv file in Excel, all values are in one column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.