Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed add forward-slash to beginning of line

Tags:

linux

sed

Want to add a forward slash to the beginning of each line in a file. Having trouble escaping the character.

Input

// input.txt
hello
world
foo
bar

Expected Output

/hello
/world
/foo
/bar

Command Tried

cat input.txt | sed 's/^/\/\\/'

Output of Command Tried

/\hello
/\world
/\foo
/\bar

Any insights is appreciated

like image 980
Bens Steves Avatar asked Jan 31 '26 08:01

Bens Steves


1 Answers

$ cat input.txt | sed 's/^/\//'
/hello
/world
/foo
/bar
like image 59
mask8 Avatar answered Feb 03 '26 02:02

mask8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!