Bens Steves
Bens Steves

Reputation: 2849

Sed add forward-slash to beginning of line

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

Upvotes: 3

Views: 1059

Answers (1)

mask8
mask8

Reputation: 3638

$ cat input.txt | sed 's/^/\//'
/hello
/world
/foo
/bar

Upvotes: 4

Related Questions