Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cat a file Multiple times Without A Loop

Tags:

bash

shell

unix

This is NOT a homework question, this is a question from an old exam, so anyone giving an answer will not be contributing to academic dishonesty. For those still skeptical, I am simply seeking what command I could use for this.

You have a file called one_mb which is exactly 1 megabyte in size. You want to create from it a file of exactly 128 megabytes in size. Please write a shell script to do this with at most 9 lines and no loops, if statements, recursion, or any other logic control structures. Each command, including parameters, must be less than 100 characters in length.

I began to research xarg, but could not figure out a good way to use it to accomplish this.

like image 779
Mickey Sweatt Avatar asked Mar 20 '13 02:03

Mickey Sweatt


2 Answers

Not sure if this counts, but this came to mind:

seq 1 128 | xargs -Inone cat one_mb >> 128_mb

No loops were used, just a pipe and xargs.

like image 180
Rain Avatar answered Oct 11 '22 02:10

Rain


Assuming bash, you can use a one-line brace expansion hack:

cat one_mb{,}{,}{,}{,}{,}{,}{,} > 128_mb
like image 20
Josh Cartwright Avatar answered Oct 11 '22 01:10

Josh Cartwright