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
# 8  
Old 12-29-2010
For rdcwayx error, please post the command you tried.
and
what do you mean by "they are unfortunately NOT the same thing."
In your example input, they look same. Also blue section seems to be telling the populated feilds i.e.
in cell137-1/2/3 line, CFRPHEM1, CFRPHEM2 and CFRPHEM3 are populated (Not CFRPHEM4, CFRPHEM5 etc).
Please post some example input showing "they are unfortunately NOT the same thing." and expected output.
# 9  
Old 12-29-2010
for rdcwayx error, i have posted:
Code:
nawk '/cell/ {split($3,a,"[-/]"); for (i=2;i<=length(a);i++) {if ($(i+2)!="111111" ) print a[1],a[i]}}' file1.txt

since my machine is solaris, i have to use nawk.

they are not the same because on the following lines in my text, i have realized that:
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               
...
...
...
  8  Iub41    cell413-1/2/3/1/2/3  LLLLLL    111111   111111   111111   011111   L00000  1111   A   
...
...             
---------------------------------------------------------------------------------------------------------------------

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 %)

Smilie
# 10  
Old 12-29-2010
Code:
awk '/cell/ {n=split($3,a,"[-/]"); for(i=2;i<=n;i++) if($(i+2) != "111111") print a[1],i-1}' file1.txt

If on Solarish, Just replace awk with nawk.
This User Gave Thanks to anurag.singh For This Post:
# 11  
Old 12-29-2010
thanks dude. you are again perfect Smilie
# 12  
Old 12-29-2010
Quote:
Originally Posted by anurag.singh
Code:
awk '/cell/ {n=split($3,a,"[-/]"); for(i=2;i<=n;i++) if($(i+2) != "111111") print a[1],i-1}' file1.txt

If on Solarish, Just replace awk with nawk.
Something is wrong in the red part. For my understand, the red part should be replaced by a[i]

Code:
# Because nawk don't support length(ARRAY) function. So that's the good point to change the code by n=split($3,a,"[-/]")

nawk '/cell/ {n=split($3,a,"[-/]"); for (i=2;i<=n;i++) {if ($(i+2)!="111111" ) print a[1],a[i]}}' file.txt

But gc_sw has given the thanks to it, so maybe I am wrong.
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