Format Unrar List as Machine-Readable Columns

Parsing the contents of a RAR archive from the command line often requires transforming human-readable tables into clean, structured data suitable for automated scripts and pipelines. By default, the unrar utility prints decorative headers, horizontal rule lines, and summary footers that break standard parsers. This guide demonstrates how to suppress formatting artifacts using native unrar listing flags and pipe the output into standard stream editors to generate structured, column-delimited formats like TSV or CSV.

Method 1: Bare Listing (File Paths Only)

If your workflow only requires a list of file paths without metadata, use the lb (list bare) switch:

unrar lb archive.rar

This outputs one relative file path per line, stripping away all banners, headers, and file attributes.

Method 2: Technical Listing (unrar lt) with awk

For multi-column data including file sizes, timestamps, and attributes, the lt (list technical) switch provides key-value blocks for each entry, making it the most reliable source for machine-readable extraction.

You can parse these blocks into tab-separated values (TSV) using awk:

unrar lt archive.rar | awk -F': ' '
    /^Name/ { name = $2 }
    /^Size/ { size = $2 }
    /^Type/ { type = $2 }
    /^mtime/ { mtime = $2 }
    /^Attributes/ {
        attr = $2
        if (name != "") {
            print name "\t" size "\t" type "\t" mtime "\t" attr
        }
        name = size = type = mtime = attr = ""
    }
'

This outputs standard columns:

  • Column 1: File Name
  • Column 2: Uncompressed Size (bytes)
  • Column 3: Type (File/Directory)
  • Column 4: Modification Time
  • Column 5: File Attributes

Method 3: Stripping the Standard Verbose Table (unrar v)

The standard verbose list (unrar v) outputs a fixed-width table. To extract columns directly, use sed to strip the non-data header lines and footer summaries, then parse the remaining rows.

unrar v -c- archive.rar | sed -e '1,/^---/d' -e '/^---/,$d' | awk '{
    # Size is $1, Packed is $2, Ratio is $3, Date is $4, Time is $5, Attr is $6
    # Filename starts at column 7 and may contain spaces
    size = $1; packed = $2; ratio = $3; date = $4 " " $5; attr = $6
    $1=$2=$3=$4=$5=$6=""; sub(/^[ \t]+/, "")
    print size "\t" packed "\t" ratio "\t" date "\t" attr "\t" $0
}'

The -c- switch disables archive comments to prevent unexpected text from disrupting line counts.

Best Practices for Automation

  • Use Tab Delimiters (\t): Because filenames inside archives frequently contain spaces, avoid space-separated columns.
  • Disable Comments: Always append -c- when invoking unrar in automated scripts to ensure archive-level comments do not interfere with line parsers.
  • Check Return Codes: Ensure your script monitors exit code 0 from unrar prior to piping into formatting utilities to avoid parsing incomplete or corrupted outputs.