unrar List Files in Comma Separated Format
The unrar utility does not provide a native flag to
export archive contents directly as comma-separated values (CSV).
However, you can achieve this by pairing the bare-listing command of
unrar with standard command-line stream-processing tools.
This guide demonstrates how to generate a clean, comma-separated list of
files from a RAR archive on Linux, macOS, and Windows.
The Base Command:
unrar lb
To format the output easily, you must avoid the default listing modes
(unrar l or unrar v), which include table
headers, file sizes, permissions, and summary footers. Instead, use the
lb (list bare) switch:
unrar lb archive.rarThis prints only the file paths, exactly one per line, making it suitable for piping into text manipulation utilities.
Method 1: Linux and macOS
(Using paste)
The cleanest and most efficient tool for joining lines with a
delimiter is paste.
Run the following command in your terminal:
unrar lb archive.rar | paste -sd, --s: Merges lines sequentially instead of in parallel columns.-d,: Sets the delimiter to a comma.-: Reads from standard input (stdin).
To save the result to a text or CSV file, redirect the output:
unrar lb archive.rar | paste -sd, - > filelist.csvMethod 2: Linux and macOS
(Using tr)
If paste is unavailable, you can translate newlines into
commas using tr. Since tr replaces every
newline, it leaves a trailing comma at the end of the line, which can be
stripped using sed:
unrar lb archive.rar | tr '\n' ',' | sed 's/,$//'Method 3: Windows PowerShell
On Windows, PowerShell provides built-in array handling that can join items directly using a specified character.
Run the following command in PowerShell:
(unrar lb archive.rar) -join ','To output the result to a file:
((unrar lb archive.rar) -join ',') | Out-File -Encoding utf8 filelist.csvHandling Spaces and Special Characters
If the filenames inside the RAR archive contain spaces or special characters, you may need each file wrapped in double quotes for proper CSV compliance.
In Bash (using awk):
unrar lb archive.rar | awk '{printf "%s\"%s\"", (NR>1 ? "," : ""), $0}'In PowerShell:
((unrar lb archive.rar) | ForEach-Object { "`"$_`"" }) -join ','