2

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 garbage to go through.

1 Answer 1

1

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.

You must log in to answer this question.

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