Getting phone number, its message and assigning them into 2 variables then screen output.

Hi Everyone,

I have a flatfile "inbox.txt" which contains some information:

Location 0, folder "Inbox", SIM memory, Inbox folder
SMS message
SMSC number : "+24800000023"
Sent : Sat 04 Aug 2012 09:01:00 PM +0700
Coding : Default GSM alphabet (no compression)
Remote number : "+24705320988"
Status : Read

This is message 1

Location 1, folder "Inbox", SIM memory, Inbox folder
SMS message
SMSC number : "+24800000023"
Sent : Sat 04 Aug 2012 09:02:36 PM +0700
Coding : Default GSM alphabet (no compression)
Remote number : "+24705320988"
Status : UnRead

This is message 2

2 SMS parts in 2 SMS sequences

I just want to get phone' number and its message and output them to screen. it should be output as :

+24705320988
This is message 1
+24705320988
This is message 2

Could someone help me by shell script? . Thanks in advance

Try this:

awk 'p&&length{p=x;print}
/Remote number/{
   gsub(/.*Remote number : ./,"");
   gsub(/\".*/,"");print;p++}' RS= inbox.txt
1 Like

Thanks for you reply but the result does not display phone number

awk -F"\n" '
BEGIN{RS="Location"}
{for (i=1;i<NF;i++){if($i ~ /Remote number/)
	{
		split($i,a,":");
		gsub("\"","",a[2]);
		print a[2];flag=1};
		if(length($(i+2))>0&&flag==1)
			{
				flag=0;
				print $(i+2);
				next
			}
	}
}' inputfile
1 Like

Thanks raj_saini20 so much. I got it !!! I read you code but i dont understand why there is a space before phone' number on screen output. Could you explain for me ?

Same is because it is present in the file after ":". it can be removed by using gsub() command if you want.