[Solved] Limit output to 5 items [duplicate]


you can use the head command to limit the output of grep to the first 5 results before passing it to xargs.

Here’s the modified command:

grep -r -l 'foo' | head -n 5 | xargs sed -i 's/foo/bar/g'

For items 5 to 10, you can use a combination of head and tail commands to achieve that.

Here’s the command to process items 5 to 10:

grep -r -l 'foo' | head -n 10 | tail -n 6 | xargs sed -i 's/foo/bar/g'

1

solved Limit output to 5 items [duplicate]