1

I am executing shell file like this in terminal:

./cherrypicker.sh input.txt

input.txt contains input text.

My purpose is to pass input text directly as command line argument from web interface

I checked cherrypicker.sh file, to get some clue. it has

tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

If $1 would have been text from input.txt then I could have passes text directly. But when I do echo $1 it give input.txt.

I could not understand what is > indicates here and also 2 and /dev/null

Any explaination would be much appreciable. I checked about .sh file but articles says it's shell file equavalent to .bat file

Cherrypicker.sh

#!/bin/bash

echo "running stanford pos tagger..."
tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

echo $1.pos

echo "running stanford ner tagger..."
tools/ner/ner.sh tools/ner $1 > $1.ner 2> /dev/null

echo "running charniak parsing..."
java MakeCharniakInput $1
tools/charniak-parser/PARSE/parseIt -l300 tools/charniak-parser/DATA/EN/ $1.charniakIN > $1.charniak

echo "running minipar parsing..."
tools/minipar/pdemo/pdemo -p tools/minipar/data/ < $1 > $1.minipar

echo "detecting mentions..."
java MentionDetection $1
tools/crf++/crf_test -m modelmd $1.crf > $1.pred
java CreateNPSpan $1 $1.pred


# if [[  $1 = "mp" ]]
# then
#   echo "creating feature file...."
#       java -cp .:edu.mit.jwi.jar CherryPick mp raw.txt
#       echo "classifying clusters using $1 model....."
#       tools/svmmentionpair/svm_classify raw.txt.mpsvm modelmp raw.txt.mppred
#       java MakeCluster raw.txt raw.txt.mppred
#   elif  [[ ( $1 = "mr" ) || ( $1 = "cr" )  ]]
#   then
    echo "creating feature file...."
    java -cp .:edu.mit.jwi.jar CherryPick cr $1
    echo "classifying clusters using cr joint model....."
    tools/svmrank/svm_classify $1 modelrank > $1.entities
#   else
#       echo "cannot classify clusters using *mysterious* model....."
#   fi


echo "creating output....."
java MakeResponse $1
1
  • 1
    cherrypicker.sh expects as input a filename, not some text. As the various programs used in this script also expect a filename and cannot be given some text directly (in particular "java"), you first need to create a file containing your text, then pass it to the script. Commented Sep 18, 2014 at 7:58

2 Answers 2

2

Command:

   tools/pos/pos.sh tools/pos $1 > $1.pos 2> /dev/null

Explanation:

tools/pos/pos.sh  - script

tools/pos         - Positional argument 1 for pos.sh

$1                - Positional argument 2 for pos.sh

$1.pos            - Is a file which will hold the standard output of pos.sh

/dev/null         - is a null file which will hold standard error

The tools/pos/pos.sh takes two postional arguments in this case tools/pos & $1(input.txt) does its work

and redirects the standard output of tools/pos/pos.sh to file $1.pos(input.txt.pos) ,the part > $1.pos of the command does this and

the part 2> /dev/null of the above command redirects the standard error to /dev/null

Sign up to request clarification or add additional context in comments.

8 Comments

thanks dear, can you please tell me in ./cherrypicker.sh input.txt how can I directly pass the input text rather text file name. I have edited the question with shell file content
The short answer is: You can't, you need to create a file containing your text and pass the name of this file.
As @Lars Noschinski suggested you can't pass the contents of the file and you don't have to , the ./cherrypicker.sh expects the file name as arguments and the cherrypicker uses this file name inturn to pass the file name as argument to other command and scripts used within the cherrypicker.sh , passing the contents of file name to cherrypicker.sh will break the script
@Ram and Lars: thanks, but issue is I am getting input from gearman worker as a "string text". can I do like echo <input text> > input.txt when ever I get request to proceed. and at the end executing rm input.* to remove generated files, so that next time fresh input is considered?
@user123 yeah you can do echo "$stringText" > input.txt before running the cherrypicker.sh input.txt and you don't have to remove the input.txt, since the single > redirection will overwrite the input.txt with contents of $stringText each time echo "$stringText" > input.txt is executed. Does this help?
|
2

1) > and 2> manipulate standard output and standard error stream redirection respectively, so your output goes into $1.pos and error is redirected to /dev/null (discarded)

2) if you want to feed the content of a file as input, then you can redirect the file as input, e.g.:

tools/pos/pos.sh tools/pos < $1 > $1.pos 2> /dev/null

or through a pipe:

cat $1 | tools/pos/pos.sh tools/pos > $1.pos 2> /dev/null

3) if you want the file contents as an argument (I hope input.txt is just one line), then try this:

tools/pos/pos.sh tools/pos `cat $1` > $1.pos 2> /dev/null

or you can try xargs to execute your command once per line:

cat $1 | xargs -I myargs tools/pos/pos.sh tools/pos myargs >> $1.pos 2> /dev/null

here >> means standard output is appended to the same file.

3 Comments

thanks dear, can you please tell me in ./cherrypicker.sh input.txt how can I directly pass the input text rather text file name. I have edited the question with shell file content
use xargs for invoking your command for each line: cat input.txt | xargs ./cherrypicker.sh
btw, you can lookup all this information in a manual, like: "man xargs" it is a steep learning, but it is worth it (Unix interface hasn't changed for many years).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.