Stripping @@@ in the data line

February 7, 2011 at 04:10:44
Specs: Linux x86_64
Hi,
I have a data as follows...

Model4@@@45-678@@@-@@@45/89@@@-@@@-@@@-@@@Jane@vcom.com-@@@-

I want to strip "@@@" and save it in another array without those "@@@" like ...

Model4 45-678 - 45/89 - - - Jae@gmail.com -

I tried like this

dbarray=( $(echo ${l2} | tr "@@@" "\n") )

But problem is, tr command is striping even Email ID @ too, so it is printing as " jae gmail.com"
Can anybody help to solve this issue.

Thanks,


See More: Stripping @@@ in the data line

Report •

#1
February 7, 2011 at 09:22:56
You can use sed to replace only 3-@:

#!/bin/bash

i2="Model4@@@45-678@@@-@@@45/89@@@-@@@-@@@-@@@Jane@vcom.com-@@@-"

echo "$i2"|sed 's/@@@/ /g'

My question is: are you trying to place every element delimited by @@@ into a bash array?


Report •

#2
February 7, 2011 at 12:12:22
I am going to assume you do to build a a bash array where every element in a string is delimited by @@@.

I have been thinking about this and I don't seem to be able to replace @@@ with a new-line. However, choose a character that is not used in the string (I know, that might be a severe limitation) and replace every @@@ with that character. I choose the pipe symbol, |

#!/bin/bash

i2="Model4@@@45-678@@@-@@@45/89@@@-@@@-@@@-@@@Jane@vcom.com-@@@-"

{
IFS="|"
array_name=( $(echo "$i2"|sed 's/@@@/|/g'))
}
echo ${array_name[@]} # Model4 45-678 - 45/89 - - - Jane@vcom.com- -


Report •

#3
February 7, 2011 at 22:06:56
Thanks for your replies.

Yes, I want to store in an array.

Your solution worked.


Report •
Related Solutions


Ask Question