0

我正在尝试做出如下提示:

脚本:输入文件名

用户: data.pdf

脚本:输入你想要的数据.pdf

用户: 2

然后它在我的输出文件中输出 2 个 data.pdf,这是我目前正在尝试的,但它不起作用:

 PROMPT_TEXT='Enter the filename:'
 PROMPT_TEXT='Enter the Number of that files you want outputted'
 read -p "$PROMPT_TEXT" filename
 read -p "$PROMPT_TEXT" amount
 grep -m "$amount" "$filename" input.txt > output.csv
 echo "**Stored Successfully in output.txt**";;

如果有帮助,这是输入文件:

FilePath  Filename  Probability ClassifierID    HectorFileType  LibmagicFileType
/mnt/Hector/Data/benign/binary/benign-pete/ 01d0cd964020a1f498c601f9801742c1    19  S040PDFv02  data.pdf    PDF document
/mnt/Hector/Data/benign/binary/benign-pete/ 0299a1771587043b232f760cbedbb5b7    0   S040PDFv02  data.pdf    PDF document

谢谢你

4

2 回答 2

2

等到你读完文件名来创建第二个提示:

PROMPT_TEXT='Enter the filename:'
read -p "$PROMPT_TEXT" filename
PROMPT_TEXT="Enter the amount of $filename you want outputted"
read -p "$PROMPT_TEXT" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**"
于 2013-08-22T18:10:06.207 回答
2

你没说是什么问题。我假设您两次收到相同的提示。您需要将两个提示定义为单独的变量:

PROMPT_TEXT1='Enter the filename:'
PROMPT_TEXT2='Enter the Number of that files you want outputted'
read -p "$PROMPT_TEXT1" filename
read -p "$PROMPT_TEXT2" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**";;

或者,完全取消它们:

read -p "Enter the filename:" filename
read -p "Enter the Number of that files you want outputted:" amount
grep -m "$amount" "$filename" input.txt > output.csv
echo "**Stored Successfully in output.txt**";;
于 2013-08-22T18:12:04.467 回答