Help to get some string in a file and make it into columm


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help to get some string in a file and make it into columm
# 1  
Old 02-20-2014
Help to get some string in a file and make it into columm

Hi all,

newbie here Smilie
I need ur help to grep ISDN number in a file with certain Global title number in a file.
for example
Code:
INTERNATIONAL MOBILE SUBSCRIBER IDENTITY ...... 510aaaaaaaaaa 
        MOBILE SUBSCRIBER INTERNATIONAL ISDN NUMBER ... 628bbbbbbbbb  
        SERVING SMMU UNIT INDEX ....................... 03
        NETWORK ACCESS MODE ........................... BOTH GSM AND GPRS
        RADIO ACCESS TYPE ............................. GERAN
        TERMINAL TYPE ................................. GPRS AND UMTS
        SUBS ACCESS CAPABILITY (HLR PROFILE) .......... GPRS ONLY
        LA MOBILE COUNTRY CODE ........................ AAA
        LA MOBILE NETWORK CODE ........................ BB 
        LOCATION AREA CODE ............................ 1SSSSSS
        SERVICE AREA CODE ............................. FDDDDD
        ROUTING AREA CODE ............................. BBBBB
        CELL IDENTITY ................................. HHHHHH
        DRX PARAMETER
          SPLIT PG CYCLE CODE ......................... 8  
          NON DRX TIMER ...............................  2
          SPLIT ON CCCH ............................... N
        NETWORK CAPABILITY
          CIPHERING ALGORITHM ......................... GEA2
          SM CAPABILITIES VIA DEDICATED CHANNELS ...... Y
          SM CAPABILITIES VIA GPRS CHANNELS ........... Y
          UCS2 SUPPORT ................................ Y
          SS SCREENING INDICATOR ...................... 1  
        GPRS DETACH FLAG .............................. OFF
        MOBILE NOT REACHABLE FOR GPRS FLAG (MNRG)...... OFF
        NON-GPRS ALERT FLAG (NGAF)..................... OFF
        CIRCUIT SWITCHED CALL FLAG .................... OFF
        ROAMING RESTRICTED............................. N
        CHARGING CHARACTERISTICS....................... NOT DEFINED
        CAMEL SUBSCRIPTION INFORMATION
          SMS-CSI
            SCP ADDRESS ............................... 628zzzzzzz     
            SERVICE KEY ............................... 110
            TDP ....................................... COLLECTED INFO
            DEFAULT SMS HANDLING ...................... RELEASE TRANSACTION 
        HLR-ADDRESS
          GLOBAL TITLE ................................ 628xxxxxxxxx      
          NUMBERING PLAN .............................. E.164           
          NATURE OF ADDRESS ........................... INT             
        VLR-ADDRESS ................................... NO ASSOCIATION

        SHORT MESSAGE SERVICE
          MT-SHORT MESSAGE POINT TO POINT (T21)........ ON
          MO-SHORT MESSAGE POINT TO POINT (T22)........ ON



the output that i want is should be like this, separate in columm
Code:
GLOBAL TITLE  628xxxxxxxxx    MOBILE SUBSCRIBER INTERNATIONAL ISDN NUMBER  628bbbbbbbbb

i dont know where i start to begin to process it,, thanks for your help. i'll appreciate
# 2  
Old 02-21-2014
Hi fikamw,
Your certain number is '628xxxxxxxxx' in your example, right ?
try this
Code:
awk '$2==str1{
s=$3
}
$2==str2{
if($3==gtnum){
print str2,$3,str1,s
}
}' FS='[ .]{2,}' OFS=' ' str1='MOBILE SUBSCRIBER INTERNATIONAL ISDN NUMBER' str2='GLOBAL TITLE' gtnum='628xxxxxxxxx' infile

cheers.

Lucas
# 3  
Old 02-21-2014
Try :
Code:
$ awk '/ISDN/{I=$0}/GLOBAL TITLE/{$0 = $0 FS I; gsub(/\./,x,$0); $1=$1; print;exit}' file

# 4  
Old 02-21-2014
This is one way:
Code:
IFS_BAK=${IFS}
IFS=$'\n'
arr=(`grep -E "GLOBAL TITLE.*628xxxxxxxxx|MOBILE SUBSCRIBER INTERNATIONAL ISDN NUMBER.*628bbbbbbbbb" your_file_name`)
MOBILE=`echo ${arr[0]} | sed 's/^[ \t]*//;s/[ \t]*$//;s/\.*//g'`
GLOBAL=`echo ${arr[1]} | sed 's/^[ \t]*//;s/[ \t]*$//;s/\.*//g'`
echo "$GLOBAL    $MOBILE"
IFS=${IFS_BAK}

$ test.sh
Code:
GLOBAL TITLE  628xxxxxxxxx    MOBILE SUBSCRIBER INTERNATIONAL ISDN NUMBER  628bbbbbbbbb

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. Shell Programming and Scripting

Removing string from CSV file by provide removal string from other file

What I need is to remove the text from Location_file.txt from each line matching all entries from Remove_location.txt Location_file.txt FlowPrePaid, h3nmg1cm2,Jamaica_MTAImageFileFlowPrePaid,h0nmg1cm1, Flow_BeatTest,FlowRockTest FlowNewTest,FlowNewTest,h0nmg1cm1 PartiallySubscribed,... (3 Replies)
Discussion started by: ketanraut
3 Replies

3. UNIX for Beginners Questions & Answers

Search a string and display its location on the entire string and make a text file

I want to search a small string in a large string and find the locations of the string. For this I used grep "string" -ob <file name where the large string is stored>. Now this gives me the locations of that string. Now how do I store these locations in a text file. Please use CODE tags as... (7 Replies)
Discussion started by: ANKIT ROY
7 Replies

4. Shell Programming and Scripting

Egrep how to make sure string is after 5 comma

Hello, Need help... using egrep how do I make sure string is after 5th comma example: a,b,c,d,e,f,g,h,i Suppose i want to search letter f but want to make sure it is after 5th comma. Is there any way to check string is after 5th comma? Thanks !! (9 Replies)
Discussion started by: vegasluxor
9 Replies

5. Shell Programming and Scripting

How to make sure the input string is one of many options?

How to make sure the input string is one of many options e.g centos-5.5-i386 windows-2003r2-x64 ? The options are dynamic, so "case" condition check doesn't work. I use grep -o -w , it doesn't work every time because - is valid word boundry #word windows-2003 failed the check as expected... (4 Replies)
Discussion started by: honglus
4 Replies

6. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

7. Shell Programming and Scripting

How to make a long print string to shotcut form in perl?

print "1.readfromfile\n2.add_ex1(4,5)\n3.add_ex2(11,5)\n4.add_ex3(9,3)\n5.add_ex4(91,4)\n"; How to do it in this form: print "1.readfromfile\n 2.add_ex1(4,5)\n 3.add_ex2(11,5)\n 4.add_ex3(9,3)\n 5.add_ex4(91,4)\n"; (3 Replies)
Discussion started by: cola
3 Replies

8. Shell Programming and Scripting

Extracting particular string in a file and storing matched string in output file

Hi , I have input file and i want to extract below strings <msisdn xmlns="">0492001956</ msisdn> => numaber inside brackets <resCode>3000</resCode> => 3000 needs to be extracted <resMessage>Request time getBalances_PSM.c(37): d out</resMessage></ns2:getBalancesResponse> => the word... (14 Replies)
Discussion started by: sushmab82
14 Replies

9. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Programming

How to make static unicode string?

In Windows, wchar_t *pStr = L"Hello"; works, but I can't find the equivalent to Unix system. How can I make static stack-memory-based wide character string in C in Unix? (1 Reply)
Discussion started by: sledge76
1 Replies
Login or Register to Ask a Question