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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting phone number, its message and assigning them into 2 variables then screen output.
# 1  
Old 08-07-2012
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
# 2  
Old 08-07-2012
Try this:

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

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 08-07-2012
Quote:
Originally Posted by Chubler_XL
Try this:

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



Thanks for you reply but the result does not display phone number
# 4  
Old 08-07-2012
Code:
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

This User Gave Thanks to raj_saini20 For This Post:
# 5  
Old 08-07-2012
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 ?

Last edited by testcase; 08-07-2012 at 05:24 AM..
# 6  
Old 08-07-2012
Same is because it is present in the file after ":". it can be removed by using gsub() command if you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Auto phone number search

Hi. I want to search 10 phone numbers automatically in Facebook and store the result in some format. Can anyone help me with the script. I am using kali Linux. (2 Replies)
Discussion started by: looksthatmatter
2 Replies

2. Shell Programming and Scripting

Assigning Variables

Hi, Can the below be clarified please. i just want to know what is the difference between the two ways of assigning variables as mentioned below. export SRC_TBL=${SRC_TBL-"MMA_COPAY_PLN_FACT_STG"} export SRC_TBL="MMA_COPAY_PLN_FACT_STG" thanks in advance :) Arun (1 Reply)
Discussion started by: Arun Mishra
1 Replies

3. Shell Programming and Scripting

Editing phone number with multiple delimiters

Hello all I have a data base of information that is formatted like so: JSD4863 XXX-XX-XXXX DOE, JOHN C JR-II BISS CPSC BS INFO TECH 412/779-9445 I need the last four digits of the phone number. However, many lines contain 'garbage data' that I'm not interested in. So i used a 'for loop'... (7 Replies)
Discussion started by: smartSometimes
7 Replies

4. Shell Programming and Scripting

Assigning variables

i have variables RECIPIENTS_DEVL,RECIPIENTS_UACC,RECIPIENTS_PROD i have a case statement to get the phase variable: case ${WMD_UPHASE1} in u) WMD_UPHASE4=UACC;; i) WMD_UPHASE4=DEVL;; p) WMD_UPHASE4=PROD;; d) WMD_UPHASE4=DEVL;; *) WMD_UPHASE4=DEVL;; esac I am unable to... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

5. Shell Programming and Scripting

Need help in assigning output of n commands to n variables automatically inside a for loop

Please help me to automatically assign the output of awk command to the variables cs3, cs4, cs5 and cs6 using a for loop. The below code is not working. for i in 3 4 5 6 do cs$i=`awk -F"|" 'BEGIN{sum=0}{sum=sum+$'$i'}END{printf("%d\n", sum)}' css` done echo $cs3 $cs4 $cs5 $cs6 (9 Replies)
Discussion started by: thulasidharan2k
9 Replies

6. Shell Programming and Scripting

Perl script :- Phone number validation

Hi All, I am doing a perl script validation for Phone numbers. The normal phone number format is 01-32145. I need to do two validations for the phone number 1) A valid phone number can have at least two digits as prefix and at least five digits as postfix. e.g. 01-01011 2) A... (5 Replies)
Discussion started by: subin_bala
5 Replies

7. Shell Programming and Scripting

variables not assigning in a function

Hi GUYS, I have function. I am assigning a line count to count variable. But it is throwing an error at this line. function_recur (){ #file being created in this function lenth = `wc -l function_outpu.dat`; echo $lenth; } this is the error i got rec.ksh: lenth: not found. ... (3 Replies)
Discussion started by: mac4rfree
3 Replies

8. UNIX for Dummies Questions & Answers

assigning variables from standard output

What am I doing wrong? I was searching for the answer to assigning variables from output. I found this simple response ls -l apply_want.m | read perms links owner group size mtime1 mtime2 mtime3 file this should allow me to echo the variables echo "$perms | $links | $owner | $group |... (2 Replies)
Discussion started by: whamchaxed
2 Replies

9. Shell Programming and Scripting

Assigning nawk output to variables

I do a lot of command line scripting to capture data from files or other command output. I've checked in a number of Unix and scripting books but for the life of me I can't find out how to asign field data from nawk output into variables that I can manipulate later. For example, reading a two... (6 Replies)
Discussion started by: steveje0711
6 Replies

10. UNIX for Dummies Questions & Answers

assigning variables

Before I even attempt this, is it possible to grep for a pattern, maybe a partial sentence like "go to page 3", assign that to a variable and then use awk or something to pull out the 3 and assign it to a variable? So first I would have Gotopg = "go to page 3" then page = 3 (9 Replies)
Discussion started by: k@ssidy
9 Replies
Login or Register to Ask a Question