Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk to choose text 2

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have a file file_in.txt that has the below text in it:

MO CELL CHGR
RXOTG-11 B00227A 0
B00227B 0
B00227C 0
B00227A 1
B00227B 1


I want to only send the below to a file:

B00227A
B00227B
B00227C
B00227A
B00227B

So when CELL is found, print only the fields below it to a file > file_out

There may be only one field below sometimes, sometimes more.

Thanks for the assistance!
Beaster

 
NF == 2 { print $1 > file_out } vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 

Hi Beaster!

You can try this awk command:

Code:
awk '/CELL/ { swPrint = 1; next }  swPrint = 1 { print substr($0, 22, 7 )}' file_in.txt > file_out.txt

Bye!

KP.
 
I realized, that my though process of what I actually needed, hit the dirt. I hope you don't mind a rephrase, sorry.

I have text similiar to below in a file. CELL will always be there, but the text below CELL may be different.

MO CELL CHGR
RXOTG-11 B00227A 0
B00227B 0
B00227C 0
B00227A 1
B00227B 1

END

<RXCDP:MO=RXOTG-11;

RADIO X-CEIVER ADMINISTRATION
MANAGED OBJECT CONFIGURATION DATA

MO RESULT ARFCN MISMATCH
RXORX-11-0 CONFIG HOP NONE
RXORX-11-2 CONFIG HOP NONE
RXORX-11-4 CONFIG HOP NONE
RXORX-11-5 CONFIG HOP NONE
RXORX-11-6 CONFIG HOP NONE
RXORX-11-8 CONFIG HOP NONE



I want to only send the text directly below CELL to a file:

B00227A
B00227B
B00227C
B00227A
B00227B

The hard part is, the input file will always be called file#, meaning there may be file1, file2, file3 and so on.

I need a bit of awk that looks for any file called file# and give me the output above specified, but send it to an output file of cell_out#, meaning use the number of the original file until complete.

I am very sorry for my confusion!

Beaster

 
I thought we've already dealt with that issue ;)


nawk -f beaster.awk *

#-------------- beaster.awk ------------
FNR == 1{
file_out = &quot;cell_out&quot; substr(FILENAME, match(FILENAME, &quot;[0-9]+&quot;));
}

NF == 2 {

print $1 > file_out
} vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
vgersh99,
Yea we did do that in a round about way yesterday, but today I have something similiar which kind of goes along with yesterday's issue.

How should I write the input you gave me above, along with what I need from the text I am looking for above?

Beaster-
 
save the script in a file 'beaster.awk'
and run as:

nawk -f beaster.awk * vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top