On Thu, Dec 2, 2010 at 1:10 PM, Jester Mania <jester_b84 / hotmail.com> wrote:

> Yes, but I tried the code and it is still not working.  I used a puts
> statement to output the results to see whether the "\n" text was truly
> being replaced by a tab.
>
> #!/usr/bin/ruby -w
>
> IO.readlines("input.txt").each do |line|
>   lineItem = line.gsub(/\\n/, "\t")
>   puts lineItem.split("\t")
> end
>
> However, the results were that the output still had \n text.
>
>
"\n" is a newline
"\\n" is a backslash, letter n
'\n' is the same as "\\n" but you can ignore that if it is confusing,
because it only counts when you enter it as a literal.

You say you want to see whether "\n" is being replaced by a tab, but you are
replacing /\\n/ (btw, you could use a string here). You say the output has
\n in the text. By that, I assume you mean it has a newline, but are
misinterpreting it as "\\n" which you replaced. If this is accurate, you
should decide whether you wish to replace "\n" or "\\n". As peter said,
using inspect (ie: puts line.inspect) is a good way to see your String data.

Also, if you don't already have tabs that you also wish to split on, then
you don't need the gsub step, you can just split on the "\\n". Here are a
couple of examples to hopefully make it a little easier to see.
"a\nb\\nc".split("\\n") # => ["a\nb", "c"]
"a\nb\\nc".split("\n") # => ["a", "b\\nc"]
"a\nb\\nc\td".gsub("\\n","\t").split("\t") # => ["a\nb", "c", "d"]
"a\nb\\nc\td".gsub("\n","\t").split("\t") # => ["a", "b\\nc", "d"]