search text for 111111 and get related subnames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search text for 111111 and get related subnames
# 1  
Old 12-27-2010
Power search text for 111111 and get related subnames

hi;

the problem is to search for 111111 and get related cellname.

my file1.txt is:
Code:
Following 4 sites are totally or partially unavailable:
---------------------------------------------------------------------------------------------------------------------
MOD  IUBLINK  CELLNAMES            CFRPHEM1 CFRPHEM2 CFRPHEM3 CFRPHEM4 CFRPHEM5 CFRPHEM6 ICDS   TN ATMPORTS
---------------------------------------------------------------------------------------------------------------------
  2  Iub283   cell485-1/2/3/4/5    00000L   11111L   11111L   111111   011111            1111   A                
  8  Iub125   cell326-1/2/3/4/5/6  L00000   L00000   L00000   111110   LLLLLL   000000   LLL0   A                
  8  Iub37    cell137-1/2/3        LLLLL    111111   111111                              1111   A                
 34  Iub_337  cell337-1            L00000                                                1  0    I               
...
...
...
---------------------------------------------------------------------------------------------------------------------

Cell availability: 658 of 664 cells are up (99.1 %)
Site availability: 242 of 246 sites are fully operational (98.4 %)
Unlocked Cell availability: 658 of 659 unlocked cells are up (99.8 %)

and i want to see which CFRPHEMs are NOT 111111 and related cellnames. so; as a result i want to see:
Code:
cell485 1
cell485 2
cell485 3
cell485 5
cell326 1
cell326 2
cell326 3
cell326 4
cell326 5
cell326 6
cell137 1
cell337 1
...
...
...

but confused?? SmilieSmilieSmilieSmilie
# 2  
Old 12-27-2010
Code:
awk '/cell[0-9]*-1/ {idx=index($3,"-");cell=substr($3,0,idx-1);n=split(substr($3,idx+1),a,"/"); for(i=1;i<=n;i++) if($(i+3) != "111111") print cell,a[i]}' file1.txt


Last edited by anurag.singh; 12-27-2010 at 07:39 AM..
This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 12-27-2010
thx anurag but;

the result gives:
Code:
cell485
cell485 1
cell485 2
cell485 3
cell485 5
cell326
cell326 1
cell326 2
cell326 3
cell326 4
cell326 5
cell326 6
cell137
cell137 1
cell337
cell337 1
...
...
...

i donot want cellnames without sector. would you please remove those red lines? Smilie

thx again
# 4  
Old 12-27-2010
my mistake, for loop should go from 1 to n, corrected in earlier post (it was 0 to n)
# 5  
Old 12-27-2010
thx very much anurag, you are perfect Smilie
# 6  
Old 12-28-2010
Code:
$ awk --version |head -1
GNU Awk 3.1.8

$ awk '/cell/ {split($3,a,"[-/]"); for (i=2;i<=length(a);i++) {if ($(i+2)!="111111" ) print a[1],a[i]}}' infile

# 7  
Old 12-29-2010
@rdcwayx:

i got an error:
Code:
nawk: can't read value of a; it's an array name.
input record number 5, file file1.txt
source line number 1

-------------
@anurag.singh:

result is reading sectors from blue sections but it must read from CFRPHEM sections (red ones). they are unfortunately NOT the same thing Smilie
Code:
Following 4 sites are totally or partially unavailable:
---------------------------------------------------------------------------------------------------------------------
MOD  IUBLINK  CELLNAMES            CFRPHEM1 CFRPHEM2 CFRPHEM3 CFRPHEM4 CFRPHEM5 CFRPHEM6 ICDS   TN ATMPORTS
---------------------------------------------------------------------------------------------------------------------
  2  Iub283   cell485-1/2/3/4/5    00000L   11111L   11111L   111111   011111            1111   A                
  8  Iub125   cell326-1/2/3/4/5/6  L00000   L00000   L00000   111110   LLLLLL   000000   LLL0   A                
  8  Iub37    cell137-1/2/3        LLLLL    111111   111111                              1111   A                
 34  Iub_337  cell337-1            L00000                                                1  0    I               
...
...
...
---------------------------------------------------------------------------------------------------------------------

Cell availability: 658 of 664 cells are up (99.1 %)
Site availability: 242 of 246 sites are fully operational (98.4 %)
Unlocked Cell availability: 658 of 659 unlocked cells are up (99.8 %)

we can think it as a matrix:
Code:
 get row names (cellXXX without -1/2/3/...) and column numbers (1, 2, 3, ...) where data is NOT 111111


Last edited by gc_sw; 12-29-2010 at 05:42 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search a text and return the text from file

Hi I have a set of input strings in a pattern as given below string1 string2 string3 string4 string5 I need to search this sequence of strings from a file in such a way that the first two strings (string1 and string2) and last two strings (string4 and string5) should match with the... (8 Replies)
Discussion started by: my_Perl
8 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. UNIX for Dummies Questions & Answers

Search String, Out matched text and input text for no match.

I need to search a string for some specific text which is no big deal using grep. My problem is when the search fails to find the text. I need to add text like "na" when my search does not match. I have tried this command but it does not work when I put the command in a loop in a bash script: ... (12 Replies)
Discussion started by: jojojmac5
12 Replies

4. Shell Programming and Scripting

need downloading related help...but its not related to unix

Hi All, I am trying to dowmload the zip file "zkManageCustomers.zip " but i dont have access. Can anyone help me to download this file See the below link- http://www.ibm.com/developerworks/opensource/library/wa-aj-open/index.html?ca=drs- Please help me as early as... (1 Reply)
Discussion started by: aish11
1 Replies

5. Shell Programming and Scripting

search into text

Hello, I want to search a word inside a file from a script, that is moving through a script line by line and when I find the word "hello" to cut all the text from the beginning to there and so many times successively to get the word "hello "until the end of the text. Ie if a 4 times to cut the... (6 Replies)
Discussion started by: uri_crack
6 Replies

6. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

7. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies
Login or Register to Ask a Question