Reputation: 323
I have a file withe following data
:1:aaaaa:aaa:aaa
and i want to remove the leading colon using bash to be like
1:aaaaa:aaa:aaa
Upvotes: 0
Views: 124
Reputation: 16696
As well as sed, you may get better performance for such a simple operation on a large file by using cut
:
cut myfile -d : -f 2-
You can also extract additional fields this way with other -f values.
If you want to remove the leading colon from data in a variable, such as in a loop, you can also do
myvar=":1:aaaaa:aaa:aaa"
echo ${myvar#:}
Upvotes: 0
Reputation: 8517
str=':1:aaaaa:aaa:aaa'
echo ${str:1} #=> 1:aaaaa:aaa:aaa
Resources: Bash string manipulation
Upvotes: 0
Reputation: 123458
You could use sed
:
sed 's/^://' filename
^
denotes the start of line, so ^:
would match a colon at the beginning of a line. Replace it by nothing!
Upvotes: 2