OneLinersCommand workbench
WorkspaceCommunity
Back to waiting room
COMMUNITY / LINUX

Replace the first x on each line and print the result

Replace x with y in filename

UnverifiedAI review passedExample simulation passed
sed 's/x/y/' {{name}}Not verified — review before use
0

Report this submission

Choose the clearest reason. Reports are reviewed before publication.

Command breakdown

01sed
Stream editor

Reads text from the specified file and applies the supplied editing script.

02's/x/y/'
Substitution script

Single quotes preserve the script literally in Bash. The s command substitutes the regular-expression pattern x with y. With no g flag, only the first match on each line is replaced.

03{{name}}
Input file

Path to the text file that sed reads. The file is not overwritten by this command.

Example input

$ printf 'xylophone\nexample x text\nno match\n' > sample.txt
$ sed 's/x/y/' sample.txt

Example output

yylophone
eyample x text
no match

Reproduced by the deterministic example simulator.