mao9856 has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I am very beginner of perl. I have a large data(around 10,000 columns and 13 rows) in a file with following kind of data: Below is the head -6 lines of data:
A B C . id “ABS0056”; D; E; F; G; name “SAM”; H; I; J; K;
A B C . id “ABS0059”; D; E; F; name “JOE”; G; H; I; J; K;
A B C . id “ABS0060”; D; E; F; G; name “MARY”; H; I; J; K;
A B C . id “ABS0057”; D; E; F; G; H; name “BILL”; I; J; K;
A B C . id “ABS0065”; D; E; name “RONIE”; F; G; H; I; J; K;
A B C . id “ABS0061”; D; E; F; G; name “STEPHAN”; H; I; J; K;
I want my output in following data format:
id “ABS0056”; name “SAM”;
id “ABS0059”; name “JOE”;
id “ABS0060”; name “MARY”;
id “ABS0057”; name “BILL”;
id “ABS0065”; name “RONIE”;
id ABS0061”; name “STEPHAN”
I have tried using code as below:Thank you in advance!!#!/usr/bin/perl use strict; use warnings; my$file=shift(@ARGV); my%aa=$_; open(FILE,'<',$file); while(<FILE>) { if($_=~/^# id:/ || $_=~/^# name:/) { print $_; my$entry=<FILE>; print $entry; print %aa; } } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract and print two specific keys and values using %
by toolic (Bishop) on Oct 30, 2017 at 14:46 UTC | |
|
Re: Extract and print two specific keys and values using %
by hippo (Archbishop) on Oct 30, 2017 at 14:52 UTC | |
|
Re: Extract and print two specific keys and values using %
by Discipulus (Canon) on Oct 30, 2017 at 15:05 UTC | |
|
Re: Extract and print two specific keys and values using %
by kcott (Archbishop) on Oct 31, 2017 at 07:30 UTC | |
|
Re: Extract and print two specific keys and values using %
by mao9856 (Sexton) on Oct 31, 2017 at 09:50 UTC |