Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.