Sponsored Content
Full Discussion: Reformat the data of a file.
Top Forums Shell Programming and Scripting Reformat the data of a file. Post 302474042 by samkhu on Tuesday 23rd of November 2010 07:02:55 AM
Old 11-23-2010
reformat of file

really aprecaite ur reponse. but can you please share logic in shell scritping not in perl.
Quote:
Originally Posted by pludi
This should work for the given case:
Code:
#!/usr/bin/perl -w
 
use strict;
use warnings;
 
my %data;
my $key = '';
while ( my $line = <> ) {
    chomp $line;
    next if $line =~ /^\s*$/;
    if ( $line =~ /^\w+$/ ) {
        $key = $line;
        next;
    }
    my ( $date, $content ) = ( $line =~ /^(\d+\w+)\s(.+)$/ );
    push @{ $data{$date}{$key} }, $content;
}
 
foreach my $date ( sort { $a <=> $b } keys %data ) {
    print $date, "\n";
    foreach my $key ( sort keys %{ $data{$date} } ) {
        print " ", $key, "\n";
        foreach my $content ( @{ $data{$date}{$key} } ) {
            print "    ", $content, "\n";
        }
    }
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help reformat data with awk

I am trying to write an awk program to reformat a data table and convert the date to julian time. I have all the individual steps working, but I am having some issues joing them into one program. Can anyone help me out? Here is my code so far: # This is an awk program to convert the dates from... (4 Replies)
Discussion started by: climbak
4 Replies

2. Shell Programming and Scripting

Reformat Data (Perl)

I am new to Perl. I need to reformat a data file as the last part of a script I am working on. I am stuck on this. Here is the current format: CUSTOMER Filename 09/04/07-08:49 CUSTOMER Filename 09/04/07-08:52 CUSTOMER Filename 09/04/07-08:52 CUSTOMER2 Filename 09/04/07-08:49 CUSTOMER2... (3 Replies)
Discussion started by: flood
3 Replies

3. Shell Programming and Scripting

reformat data with a shell script

Can anyone help me with a shell script that can do the following: I have a data in fasta format (first line is the header, followed by a sequence of characters). >ALLLY GGCCCCTCGAGCCTCGAACCGGAACCTCCAAATCCGAGACGCTCTGCTTATGAGGACCTC GAAATATGCCGGCCAGTGAAAAAATCTTGTGGCTTTGAGGGCTTTTGGTTGGCCAGGGGC... (5 Replies)
Discussion started by: manishabh
5 Replies

4. Shell Programming and Scripting

Help with reformat data content

input file: hsa-miR-4726-5p Score hsa-miR-483-5p Score hsa-miR-125b-2* Score hsa-miR-4492 hsa-miR-4508 hsa-miR-4486 Score Desired output file: hsa-miR-4726-5p Score hsa-miR-483-5p Score hsa-miR-125b-2* Score hsa-miR-4492 hsa-miR-4508 hsa-miR-4486 Score ... (6 Replies)
Discussion started by: perl_beginner
6 Replies

5. Shell Programming and Scripting

Help with reformat input data

Input file: 58227131 50087390 57339526 40578034 65348841 55614853 64363217 44178559 Desired output file: 58227131 50087390 57339526 40578034 65348841 55614853 64363217 44178559 Command that I try: (4 Replies)
Discussion started by: perl_beginner
4 Replies

6. Shell Programming and Scripting

Reformat MLS Data - Use AWK?

I am helping my wife set up a real estate site and I am starting to integrate MLS listings. We are using a HostGator level 5 VPS running CentOS and have full root and SSH access to the VPS. Thus far I have automated the daily FTP download of listings from our MLS server using a little sh script.... (4 Replies)
Discussion started by: Chicago_Realtor
4 Replies

7. Shell Programming and Scripting

Data reformat and rearrangement problem asking

Input file: dependent general_process dependent general_process regulation general_process - - template component food component binding data_rearrangement binding data_rearrangement specific_activity data_rearrangement - ... (7 Replies)
Discussion started by: cpp_beginner
7 Replies

8. Shell Programming and Scripting

Help with reformat data structure

Input file: bv|111259484|pir||T49736_real_data bv|159484|pir||T9736_data_figure bv|113584|prf|T4736|truth bv|113584|pir||T4736_truth Desired output: bv|111259484|pir|T49736|real_data bv|159484|pir|T9736|data_figure bv|113584|prf|T4736|truth bv|113584|pir|T4736|truth Once the... (8 Replies)
Discussion started by: perl_beginner
8 Replies

9. Shell Programming and Scripting

Help with reformat data set

Input file 4CL1 O24145 CoA1 4CL1 P31684 CoA1 4CL1 Q54P77 CoA_1 73 O36421 Unknown 4CL3 Q9S777 coumarate 4CL3 Q54P79 coumarate 4CL3 QP7932 coumarate Desired output result 4CL1 O24145#P31684 CoA1 4CL1 Q54P77 CoA_1 73 O36421 Unknown 4CL3 Q9S777#Q54P79#QP7932 coumarate I... (5 Replies)
Discussion started by: perl_beginner
5 Replies

10. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
ldns(3) 						     Library Functions Manual							   ldns(3)

NAME
ldns_key_list_key_count, ldns_key_list_key, ldns_key_rsa_key, ldns_key_dsa_key, ldns_key_algorithm, ldns_key_hmac_key, ldns_key_origttl, ldns_key_inception, ldns_key_expiration, ldns_key_keytag, ldns_key_pubkey_owner, ldns_key_flags- SYNOPSIS
#include <stdint.h> #include <stdbool.h> #include <ldns/ldns.h> size_t ldns_key_list_key_count(const ldns_key_list *key_list); ldns_key* ldns_key_list_key(const ldns_key_list *key, size_t nr); RSA* ldns_key_rsa_key(const ldns_key *k); DSA* ldns_key_dsa_key(const ldns_key *k); ldns_signing_algorithm ldns_key_algorithm(const ldns_key *k); unsigned char* ldns_key_hmac_key(const ldns_key *k); uint32_t ldns_key_origttl(const ldns_key *k); uint32_t ldns_key_inception(const ldns_key *k); uint32_t ldns_key_expiration(const ldns_key *k); uint16_t ldns_key_keytag(const ldns_key *k); ldns_rdf* ldns_key_pubkey_owner(const ldns_key *k); uint16_t ldns_key_flags(const ldns_key *k); DESCRIPTION
ldns_key_list_key_count() returns the number of keys in the key list key_list: the key_list Returns the numbers of keys in the list ldns_key_list_key() returns a pointer to the key in the list at the given position key: the key nr: the position in the list Returns the key ldns_key_rsa_key() returns the (openssl) RSA struct contained in the key k: the key to look in Returns the RSA * structure in the key ldns_key_dsa_key() returns the (openssl) DSA struct contained in the key ldns_key_algorithm() return the signing alg of the key k: the key Returns the algorithm ldns_key_hmac_key() return the hmac key data k: the key Returns the hmac key data ldns_key_origttl() return the original ttl of the key k: the key Returns the original ttl ldns_key_inception() return the key's inception date k: the key Returns the inception date ldns_key_expiration() return the key's expiration date k: the key Returns the experiration date ldns_key_keytag() return the keytag k: the key Returns the keytag ldns_key_pubkey_owner() return the public key's owner k: the key Returns the owner ldns_key_flags() return the flag of the key k: the key Returns the flag AUTHOR
The ldns team at NLnet Labs. Which consists out of Jelte Jansen and Miek Gieben. REPORTING BUGS
Please report bugs to ldns-team@nlnetlabs.nl or in our bugzilla at http://www.nlnetlabs.nl/bugs/index.html COPYRIGHT
Copyright (c) 2004 - 2006 NLnet Labs. Licensed under the BSD License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. SEE ALSO
ldns_key. And perldoc Net::DNS, RFC1034, RFC1035, RFC4033, RFC4034 and RFC4035. REMARKS
This manpage was automaticly generated from the ldns source code by use of Doxygen and some perl. 30 May 2006 ldns(3)
All times are GMT -4. The time now is 02:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy