我想N.A.
在两个连续的之间插入一个字符串,
。
这是我的绳子。
5 Local A2A SMS valid for 1 day , 10 A2A SMS valid for 2 days , 10 Local A2A SMS for 2 days only , Daily 5 Local A2A night SMS for 2 days , daily 5 local A2A night SMS for 7 days ,,,,, 5 local A2A night SMS for 2 days ,,, Outgoing Rs 40/min and Incoming Rs 30/min. Applicable only on selected countries and Operators ,,, Outgoing Rs 30/min and Incoming Rs 20/min. Applicable only on selected countries and Operators ,,,,,,,,, 5 Local night A2A SMS(11PM to 6 AM-2 days) ,, 5 Night A2A SMS for 1 Day ,, Roaming Tariff - Incoming Free, Outgoing local @ 80p/min, STD @1.15Rs/min with Talk Time 25 in main A/c ,,, 5 night local A2A sms (2 Days) ,,, Top up TT in Main a/c 95.79 + 5 A2A Night SMS. SMS valid for 2 days ,,, 300 MB 3G/4G Data , 138.51 TT(unltd val)+5 nite A2ASMS, SMS valid for 2 days , Roaming Tariff - Incoming Free, Outgoing local @ 80p/min, STD @1.15Rs/min with Talk Time 120 in main A/c ,, 500 MB 3G/4G data for 30 Days , 2 SMS valid for 2 days , 1Gb 3G/4G and 100TT , 1.5GB 3G/4G and 100TT , 2GB 3G/4G and 100TT , 2.5GB 3G/4G and 100TT , 3GB 3G/4G and 100TT , 3.5GB 3G/4G and 100TT , 4GB 3G/4G and 100TT , 200 MB 3G/4G Data , Roaming Tariff - Incoming Free, Outgoing local @ 80p/min,
例如,字符串中有5个连续的、3个连续的、6个连续的逗号。我想N.A.
在每个逗号之间插入。
,,,,,
转换为,N.A.,N.A,N.A.,N.A.,
等
答案1
使用 GNU sed:
echo "your string with commas" | sed ':a;s/,,/,N.A.,/g;ta'
:a
:名称为 a 的标签
s/,,/,N.A.,/g
: 搜索并替换所有 (g
),,
为,N.A.,
ta
:如果s///
替换成功,则分支到标签a
答案2
你可以在 bash 中这样做:
a="5 Local A2A SMS valid for 1 day , 10 A2A SMS valid for 2 days , 10 Local A2A SMS for 2 days only , Daily 5 Local A2A night SMS for 2 days , daily 5 local A2A night SMS for 7 days ,,,,, 5 local A2A night SMS for 2 days ,,, Outgoing Rs 40/min and Incoming Rs 30/min. Applicable only on selected countries and Operators ,,, Outgoing Rs 30/min and Incoming Rs 20/min. Applicable only on selected countries and Operators ,,,,,,,,, 5 Local night A2A SMS(11PM to 6 AM-2 days) ,, 5 Night A2A SMS for 1 Day ,, Roaming Tariff - Incoming Free, Outgoing local @ 80p/min, STD @1.15Rs/min with Talk Time 25 in main A/c ,,, 5 night local A2A sms (2 Days) ,,, Top up TT in Main a/c 95.79 + 5 A2A Night SMS. SMS valid for 2 days ,,, 300 MB 3G/4G Data , 138.51 TT(unltd val)+5 nite A2ASMS, SMS valid for 2 days , Roaming Tariff - Incoming Free, Outgoing local @ 80p/min, STD @1.15Rs/min with Talk Time 120 in main A/c ,, 500 MB 3G/4G data for 30 Days , 2 SMS valid for 2 days , 1Gb 3G/4G and 100TT , 1.5GB 3G/4G and 100TT , 2GB 3G/4G and 100TT , 2.5GB 3G/4G and 100TT , 3GB 3G/4G and 100TT , 3.5GB 3G/4G and 100TT , 4GB 3G/4G and 100TT , 200 MB 3G/4G Data , Roaming Tariff - Incoming Free, Outgoing local @ 80p/min,"
b=
while [ "$b" != "$a" ]
do
b="$a"
a="${a/,,/,N.A.,}"
done
echo "$a"