简体   繁体   中英

create file using grep values

I want to use the values I highlighted with grep from a file to be extracted and create a new file.

I have done the following:

grep -r "Bob-age[0-9]*\|Mark-age[0-9]*" > personInfo.txt

But I get the following error:

grep: input file 'personInfo.txt' is also the output

How can I resolve this?

If have multiple line of the file, would I have to use a loop to go through every line to get it in the file?

You need to use:

grep -r "Bob-age[0-9]*\|Mark-age[0-9]*" . > personInfo.txt

That is adding a dot as the target of grep

or more concise:

grep -r "\(Bob\|Mark\)-age[0-9]*" . > personInfo.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