Rs Command - Reshape Data with Rows and Columns | Online Free DevTools by Hexmos

Reshape data with the Rs command. Convert input into specified rows and columns, transpose output, and set dummy values. Free online tool for developers.

Rs Command

Reshape Data with Rs

The rs command is a powerful utility for reshaping data, allowing you to convert input streams into a specified number of rows and columns. This is particularly useful for reformatting tabular data or preparing output for further processing.

Basic Reshaping

To reshape data into a specific number of rows and columns, you can pipe input to the rs command. For example, to create a 4x9 grid from 36 lines of input:

# reshape data: number of rows and columns
jot 36 | rs 4 9

Handling Dummy Values

When the total number of input items doesn't perfectly divide into the specified rows and columns, you can use a dummy value. The rs command uses 0 as a default dummy value if either the row or column count is specified as 0. This is useful when you need a fixed number of columns, for instance:

# 0 is a dummy value for either the row or column count
# (4 columns)
jot 36 | rs 0 4

Transposing Output

The rs command also supports transposing output. By using the -t option, you can effectively swap rows and columns of the input data. This is achieved by specifying the number of columns for the transposed output:

# transpose output
jot 36 | rs -t 0 4

Further Resources