How to redirect `grep` output to new files?

QuestionsQuestions8 SkillsProUser Account ManagementOct, 25 2025
0247

You can redirect the output of grep to a new file using the > operator. Here's the syntax:

grep 'search_term' input_file > output_file

Example

If you want to search for the word "joker" in a file called data.txt and save the results to a file called results.txt, you would use:

grep 'joker' data.txt > results.txt

This command will create results.txt (or overwrite it if it already exists) and write all lines containing "joker" from data.txt into it.

Append Output

If you want to append the output to an existing file instead of overwriting it, use >>:

grep 'joker' data.txt >> results.txt

This will add the new results to the end of results.txt.

Let me know if you need further assistance!

0 Comments

no data
Be the first to share your comment!