Reputation: 354
I am in use of bash
shell.
I have a file filelist:
cat filelist
../1.txt
../2.txt
...
../100.txt
I want to remove "../" and I tried $ cat filelist | sed s/..\///
, but it gives an error message. How can i remove the slash?
Upvotes: 0
Views: 91
Reputation: 10039
remove starting ../
(i guess it's the purpose but not specified)
sed 's#^\.\./##' filelist
/
by #
to allow a readible /
in path^
for limiting to starting path and not changing something like bad/../folder
. If not the wanted behavior, just remove this caret.Upvotes: 1
Reputation: 96258
You need quotes:
sed 's/..\///'
.
means any character so you have to escape it too:
sed 's/\.\.\///'
and for readability you can use another character for the separator:
sed 's|\.\./||'
Upvotes: 1
Reputation: 20270
Use an alternate separator.
sed 's|^\.\./||g' filelist
You can also use the -i
flag to edit the file in-place.
sed -i 's|^\.\./||g' filelist
Upvotes: 0
Reputation: 22821
You need quotes around the sed
argument and also need to include the g
global flag. It is also not necessary to cat
the file first. You should also escape the periods.
Use:
sed 's/\.\.\///g' filelist
Gives:
1.txt
2.txt
...
100.txt
Upvotes: 1