Extract repeating data from file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extract repeating data from file
# 1  
Old 05-24-2010
Extract repeating data from file

I want to extract the last rows of a data file, similar to that one below:

C1 xxx
C2 rrr
C3 ttt
....
Cn-1 hhh
Cn bbb
C1 yyy
C2 sss
C3 uuu
...
Cn-1 iii
Cn ccc
...

I just want to extract the final rows between C1 and Cn at each data file. n is not a constant, but depends on the data itself. Is there a way to do this with awk?

Thank you,
n
# 2  
Old 05-24-2010
Assuming n is a sequence of numbers and just a single letter C before the n...
Code:
awk '{arr[$1]=$2;K=$1}END{
  for(i in arr){
    gsub(/C/,"",K)
    I=i;gsub(/C/,"",i)
      if(i<=K) print I,arr[I]}}' infile

This User Gave Thanks to malcomex999 For This Post:
# 3  
Old 05-26-2010
MySQL

thanks malcomex999Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract repeating and check for for certain error message

Hi guys I have an log from an regular application processing where the processing is done every 10 minutes and is written to the same log which is rotated on daily basis. the block of log starts always with "Starting" and ends with a certain pattern "Completed" The catch is I want to... (7 Replies)
Discussion started by: kl1ngac1k
7 Replies

2. Shell Programming and Scripting

Extract data from a file

I have a text file that contains the following data. For example, aa.txt has some numbers. I need to extract the continuous numbers(minimum 3 numbers) from it.How can I do this with awk? >aa.txt 31 35 36 37 38 39 44 169 170 173 174 175 177 206 >1a.txt 39 (5 Replies)
Discussion started by: rahmanabdulla
5 Replies

3. Shell Programming and Scripting

How to grab a block of data in a file with repeating pattern?

I need to send email to receipient in each block of data in a file which has the sender address under TO and just send that block of data where it ends as COMPANY. I tried to work this out by getting line numbers of the string HELLO but unable to grab the next block of data to send the next... (5 Replies)
Discussion started by: loggedout
5 Replies

4. Shell Programming and Scripting

Extract data from a file

Hello All, I have a small xml file which looks like below: <Check:defaultval Val="crash" value="crash_report_0013&#xA;generate_check_0020 generate_check_0022&#xA;&#xA;This is where the fault is."/> <Check:defaultval Val="crash" value="crash_report_1001&#xA;generate_check_1001... (9 Replies)
Discussion started by: suvendu4urs
9 Replies

5. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

6. Shell Programming and Scripting

Shell script to extract data in repeating tags from xml

Hi, I am new to shell scripting. I need to extract data between repeating tags from an xml file and store the data in an array to process it further. <ns1:root xmlns:ns1="http://example.com/config"> <ns1:interface>in1</ns1:interface> <ns1:operation attribute1="true" attribute2="abd"... (2 Replies)
Discussion started by: sailendra
2 Replies

7. Shell Programming and Scripting

Removing repeating lines from a data frame (AWK)

Hey Guys! I have written a code which combines lots of files into one big file(.csv). However, each of the original files had headers on the first line, and now that I've combined the files the headers are interspersed throughout the new combined data frame. For example, throughout the data... (21 Replies)
Discussion started by: gd9629
21 Replies

8. Shell Programming and Scripting

Can I split a 10GB file into 1 GB sizes using my repeating data pattern

I'm not a unix guy so excuses my ignorance... I'm the database ETL guy. I'm trying to be proactive and devise a plan B for a ETL process where I expect a file 10X larger than what I process daily for a recast job. The ETL may handle it but I just don't know. This file may need to be split... (3 Replies)
Discussion started by: john091
3 Replies

9. Shell Programming and Scripting

Extract data from file

Dear All , I am posting first time in this forum . Please ignore my mistakes . I am learning Unix and i need help to extract specific data from file . 1. I want to grep number of fails from log . The file contains "fails" word in line if test cases are failed . 2. The log contains... (20 Replies)
Discussion started by: getdpg
20 Replies

10. Shell Programming and Scripting

extract data from file

My file in ksh consists of message data of varying lengths (lines), separated with headers. I would like to find a string from this file, and print out the whole message data including the headers. my plan of attack is to search the strings, print the top header, and print the whole message... (2 Replies)
Discussion started by: apalex
2 Replies
Login or Register to Ask a Question