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"