简体   繁体   中英

How can I redirect my grep to a txt file, located in another directory?

grep -n '[0-9]' test.txt > output.txt

I would like to redirect the above grep results on to a new file (not yet created, output2.txt ), which needs to be located in another directory than the directory of test.txt . For example, maybe at nothome/labs/output2.txt . How can I do this?

您可以将绝对路径放置到输出中,如下所示:

grep -n '[0-9]' test.txt > /path/to/output/output.txt

From your posting I guess you might want to create the output path first:

OUTPUT_PATH=/path/to/output
mkdir -p ${OUTPUT_PATH}
grep -n '[0-9]' test.txt > ${OUTPUT_PATH}/output.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM