Account
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 useCommand breakdown
01
sedStream 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.txtExample output
yylophone
eyample x text
no matchReproduced by the deterministic example simulator.