Wednesday, October 5, 2022

[SOLVED] find | xargs sed to substitute string in file name instead of file content

Issue

$ echo "file_contents" > filename.txt
$ find . -type f -print0 | xargs -0 sed 's/file//g'
_contents

How do you get sed to treat the filename as a string instead of an input file? What command do I need to get "name.txt" as the output instead?


Solution

Drop the xargs and -0's.

find . -type f  | sed 's/file//g'

This takes the output of find and sends it as input to sed.



Answered By - choroba
Answer Checked By - Willingham (WPSolving Volunteer)