Extracting specific block


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting specific block
# 1  
Old 02-25-2008
CPU & Memory Extracting specific block

Hi Everyone , have a great day

i have a file which has almost 20,000 blocks each starting with this particular line " rTCCreditControlRecord " , how can i bring out the 7172 block out of that file

Thanks in Anticipation
# 2  
Old 02-25-2008
Try both the following commands.
Quote:
grep '\rTCCreditControlRecord..*$' file
or
grep '^rTCCreditControlRecord..*$' file
# 3  
Old 02-25-2008
CPU & Memory

Not working , meanwhile i have tried something like this

HTML Code:
while IFS= read -r EachLine
do
   'echo $EachLine
   if $EachLine = 'rTCCreditControlRecord'; then
   count = count + 1
   fi
   if count = 7172; then
   echo $EachLine
   fi
done < CCN02
where CCN02 is input file but its not working either
# 4  
Old 02-25-2008
Hammer & Screwdriver string vs. numeric comparisons

if count = 7172; then
>>>that is a string comparison

if count -eq 7172; then
>>>that is a numeric comparison

I think you would want the numeric comparison.
# 5  
Old 02-25-2008
Data

-r: is not an identifier

HTML Code:
#!/bin/sh
while IFS= read -r EachLine
do
   #echo $EachLine
   if $EachLine = 'rTCCreditControlRecord'; then
   count = count + 1
   fi
   if count -eq 7172; then 
   echo $EachLine
   fi
done < CCN02
Not Working Smilie
# 6  
Old 02-25-2008
Question Put in an echo to display progress

Add a display to echo to the screen what is happening. Could be count problem, $EachLine problem, file problem, etc...
By the way, wouldn't $EachLine be equal to the full line? rTCCreditControlRecord abcdefg 12345?

Code:
#!/bin/sh
while IFS= read -r EachLine
do
   #echo $EachLine
   if $EachLine = 'rTCCreditControlRecord'; then
   count = count + 1
   fi
   echo $count $EachLine   #for debug purposes
   if count -eq 7172; then 
   echo $EachLine
   fi
done < CCN02

# 7  
Old 02-25-2008
Tools Seems to be working as follows:

Code:
[ ~/tmp/tccredit ] > cat CCN02
rTCCreditControlRecord abc 001
rTCCreditControlRecord abc 002
rTCCreditControlRecord abc 003
rTCCreditControlRecord abc 004
rTCCreditControlRecord abc 005
rTCCreditControlRecord abc 006
rTCCreditControlRecord abc 007
rTCCreditControlRecord abc 008

Code:
[ ~/tmp/tccredit ] > cat cntpr
#!/bin/bash
count=0
while read EachLine
   do
   prefix=$(echo $EachLine | cut -c1-22)
   if [ "$prefix" = "rTCCreditControlRecord" ] 
      then
      count=$(($count + 1))             
      fi
   echo "debug=" $count $EachLine   #for debug purposes
   if [ $count -eq 5 ]
      then 
      echo $EachLine
      fi
done < CCN02

provides as output===>
Code:
[ ~/tmp/tccredit ] > cntpr
debug= 1 rTCCreditControlRecord abc 001
debug= 2 rTCCreditControlRecord abc 002
debug= 3 rTCCreditControlRecord abc 003
debug= 4 rTCCreditControlRecord abc 004
debug= 5 rTCCreditControlRecord abc 005
rTCCreditControlRecord abc 005
debug= 6 rTCCreditControlRecord abc 006
debug= 7 rTCCreditControlRecord abc 007
debug= 8 rTCCreditControlRecord abc 008

Note that the 5th record is what I was looking for in the process. Comment out my #debug purposes line to only get the 5th record.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add a block of code at the end of a specific block

I need to search for a block with the starting pattern say "tabId": "table_1", and ending pattern say "]" and then add a few lines before "]" "block1":"block_111" "tabId": "table_1", "title":"My title" ..... .... }] how do I achieve it using awk and sed. Thanks, Lakshmi (3 Replies)
Discussion started by: Lakshmikumari
3 Replies

2. Shell Programming and Scripting

Extracting content from a file in specific format

Hi All, I have the file in this format **** Results Data **** Time or Step 1 2 20 0.000000000e+00 0s 0s 0s 1.024000000e+00 Us 0s 0s 1.100000000e+00 1s 0s 0s 1.100000001e+00 1s 0s 1s 2.024000000e+00 Us Us 1s 2.024000001e+00 ... (7 Replies)
Discussion started by: diehard
7 Replies

3. UNIX for Dummies Questions & Answers

Filtering data -extracting specific lines

I have a table to data which one of the columns include string of text from within that, I am searching to include few lines but not others for example I want to to include some combination of word address such as (address.| address? |the address | your address) but not (ip address | email... (17 Replies)
Discussion started by: A-V
17 Replies

4. Shell Programming and Scripting

Extracting specific rows

Hi all..... I have a file which contains large data...like I want to print the rows starting from "pixel" till the file read the letter "TER" into a new output file.... can anyone plz help in doing this ?? (5 Replies)
Discussion started by: CAch
5 Replies

5. Shell Programming and Scripting

Extracting Tag along with specific lines

I have this input file: and the desired output is as follows: Desired Output This is a sample taken from a huge file. Basically, the script should take the tag (TDK11..1>) add everything that has bukle=A until it sees the blank lines. Then takes the next tag (TDK2222>) adds everything that... (4 Replies)
Discussion started by: Ernst
4 Replies

6. Shell Programming and Scripting

extracting specific text from lines

Hello, i've got this output text: and i need it to look something like this: which means that there won't be absolute path of each directory, just it's size and the last word after last '/' in each line, and i also don't need last line '1.7M /tmp' Looks like there is a simple... (5 Replies)
Discussion started by: krater559
5 Replies

7. Shell Programming and Scripting

extracting specific lines from a file

hi all, i searched in unix.com and accquired the following commands for extracting specific lines from a file .. sed -n '16482,16482p' in.sql > out.sql awk 'NR>=10&&NR<=20' in.sql > out.sql.... these commands are working fine if i give the line numbers as such .. but if i pass a... (2 Replies)
Discussion started by: sais
2 Replies

8. Shell Programming and Scripting

Extracting text out of specific lines

Hi, I have a file like LAHORE 2009-04-16 16:04:19 THU S5830 FAULT MESSAGE SUPPRESS STATUS LOC : ASP00 STS : SUPPRESSING CONTINUE INF : F6201 TRUNK. DATA FAULT REPORT COMPLETED LAHORE 2009-04-16 16:04:20 THU S8400 ISUP SIGNALLING TRACE -... (3 Replies)
Discussion started by: krabu
3 Replies

9. Shell Programming and Scripting

Extracting specific text from a file

Dear All, I have to extract a a few lines from a log file and I know the starting String and end string(WHich is same ). Is there any simplere way using sed - awk. e.g. from the following file -------------------------------------- Some text Date: 21 Oct 2008 Text to be extracted... (8 Replies)
Discussion started by: rahulkav
8 Replies

10. UNIX for Dummies Questions & Answers

Extracting specific info from finger command

Hello all, my unix is bash based and the finger command output is: Login Name Tty Idle LoginTime Office amos.john Amos John pts/26 1 Dec 5 16:18 (77.100.22.07) What am trying to achieve is extract the Login (amos.john) and Name (Amos John) from this output without using awk or sed. ... (1 Reply)
Discussion started by: franny
1 Replies
Login or Register to Ask a Question