how does apache commons-cli parses \\t character

690 views Asked by At

I need to pass tab as an argument in commons-cli. When I give the argument as "\\t", the command line parser parses it as "\t" character itself but not TAB ( ) white space. How can I achieve this?

Edit :

As suggested by @centic, updating the question with how am I calling the application. I am calling using command line in Unix where a backslash is detected as an escape character.

More precisely, I am using it while submitting hadoop streaming jobs, if this helps. For eg :

hadoop jar $HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.4.0.jar -D stream.map.output.field.separator="\t" -file mapper.py -mapper mapper.py -file reducer.py -reducer reducer.py -input /in -output /out

Apache Hadoop uses Apache Commons-cli as command line utility. So I am assuming "\\t" resolves to "\t" and passed as an option. But when I print it by debugging hadoop source code, instead of a TAB white space character, it prints as a "\t" (string literal) itself.

1

There are 1 answers

0
centic On BEST ANSWER

As you are trying to provide this when invoking the application in the shell, this is actually related to how the shell handles such special characters, not commons-cli or Java.

The shell (which is the default shell on most unix/linux versions nowadays) has the special syntax $'\t' for this, see this section in the manual.

So your call would be something like

HADOOP_HOME/share/hadoop/tools/lib/hadoop-streaming-2.4.0.jar -D 
stream.map.output.field.separator=$'\t' -file mapper.py -mapper 
mapper.py -file reducer.py -reducer reducer.py -input /in -output /out