Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

why does grep in a script run in Cygwin not maintain columnar output from a text file when it's (grep's) output is redirected to another text file - say a list of x, y coordinates marked by x and y which it can separate to 2 files (one of x coords and the other of y coords with the xs and ys being removable by sed). Instead it outputs, what started as a column of numbers, as rows of space separated numbers? I tried the Cygwin website but there's too much bullshit to go through.

share|improve this question

Probably because grep, when given two or more file name arguments, prepends the file name and a colon to each line. If the columns are delimited by tabs, the tabstops aren't going to be in the same place.

The -h option inhibits the filename prefix, and should avoid any misalignment, since grep doesn't modify its input lines (other than by prepending the file name).

You can also consider filtering the input files with expand to replace tabs with spaces.

If that doesn't solve the problem, please post some sample input and output.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .