Sponsored Content
Top Forums Shell Programming and Scripting Identify matching data in a file and output to original line, in perl Post 302264786 by Pcushing on Thursday 4th of December 2008 09:33:11 PM
Old 12-04-2008
Identify matching data in a file and output to original line, in perl

Hi,

I haven't done this for awhile, and further, I've never done it in perl so I appreciate any help you can give me.

I have a file of lines, each with 5 data points that look like this:

AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N
ALD,N,ALLIED CAPITAL CORPORATION,ALD,N
AFC,N,ALLIED CAPITAL CORPORATION,ALD,N

Let's call it: a,b,c,d,e

Every time a == d and b == e, I want to then search every other line in the file and find where a == d(newline) and a == e(newline). Whenever this is the case, I want to append the a,b data from the newline to the original line such that it reads: a,b,c,d,e,a(newline),b(newline).

Using the data above, we would output something like this:

AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N
ALD,N,ALLIED CAPITAL CORPORATION,ALD,N,AFC,N
AFC,N,ALLIED CAPITAL CORPORATION,ALD,N

I'm also not sure how many total matches there might be in the file so I could end up with ~100 matching lines for any original line such that the final result for the original line would look like: a,b,c,d,e,a(newline0),b(newline0)...,a(newline100),b(newline100)

Does that make sense?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need to identify the line containing @ in between the line of a file

Hi All, I have a huge unix flat file delimted by @ at the end of the line. I need to find out if there is any line/s containing @ in between the line so that I can remove that and put the file for processing. Thanks in advance for your help. (4 Replies)
Discussion started by: b.paramanatti
4 Replies

2. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies

3. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies

4. Shell Programming and Scripting

using perl for matching one file with another file and print into new line

One file is fileA 0.0246*0.0068*0.0013*0.0023*0.0182*0.0028*0.0019*0.4750*0.0028*0.0812*0.0123*0.0018*0.0039*0.0020*0.0028*0.0047*0.0139*0.3330*0.0017*0.0072*0.4789... (4 Replies)
Discussion started by: cdfd123
4 Replies

5. Programming

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 2365193 G A 0.0812 0.07319 1.12 ... (1 Reply)
Discussion started by: sureshraj
1 Replies

6. Shell Programming and Scripting

How to find the matching data b/w 2 files in perl?

Hi friends,, i have find the matching data between 2files. My file1 have a data like rs3001336 rs3984736 rs2840532 File2 have a data like rs3736330 1 2359237 A G 0.28 1.099 0.010 rs2840532 1 2359977 G A 0.363 0.3373 1.123 rs3001336 1 ... (4 Replies)
Discussion started by: sureshraj
4 Replies

7. Shell Programming and Scripting

perl script to replace the text in the original file

Hi Folks, I have an html file which contains the below line in the body tagI am trying the replace hello with Hello Giridhar programatically. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> I have written the below code to... (3 Replies)
Discussion started by: giridhar276
3 Replies

8. Shell Programming and Scripting

Can't Output Piped Perl In-line command to a File

Hello, I'm pretty stumped, and I don't know why I am not able to redirect the output to the 'graphme' file with the command below in Fedora 18. tcpdump -l -n -t "tcp == 18" | perl -ane '($s,$j)=split(/,/,$F,2); print "$s\n";' > graphme In case you're wondering, I was following the example... (2 Replies)
Discussion started by: ConcealedKnight
2 Replies

9. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

10. Shell Programming and Scripting

How to control grep output intact for each matching line?

I have multiple (~80) files (some can be as big as 30GB of >1 billion of lines!) to grep on a pattern, and piped the match to a single file. I have a 96-core machine so that each grep job was sent to the background to speed up the search: file1.tab chr1A_part1 123241847 123241848... (6 Replies)
Discussion started by: yifangt
6 Replies
Locale::RecodeData::INIS(3)				User Contributed Perl Documentation			       Locale::RecodeData::INIS(3)

NAME
Locale::RecodeData::INIS - Conversion routines for INIS SYNOPSIS
This module is internal to libintl. Do not use directly! DESCRIPTION
This module is generated and contains the conversion tables and routines for INIS. COMMENTS
The following comments have been extracted from the original charmap: version: 1.0 source: ECMA registry alias ISO-IR-49 Please note that aliases listed above are not necessarily valid! CHARACTER TABLE
The following table is sorted in the same order as the original charmap. All character codes are in hexadecimal. Please read 'ISO-10646' as 'ISO-10646-UCS4'. Local | ISO-10646 | Description -------+-----------+------------------------------------------------- 00 | 00000000 | NULL (NUL) 01 | 00000001 | START OF HEADING (SOH) 02 | 00000002 | START OF TEXT (STX) 03 | 00000003 | END OF TEXT (ETX) 04 | 00000004 | END OF TRANSMISSION (EOT) 05 | 00000005 | ENQUIRY (ENQ) 06 | 00000006 | ACKNOWLEDGE (ACK) 07 | 00000007 | BELL (BEL) 08 | 00000008 | BACKSPACE (BS) 09 | 00000009 | CHARACTER TABULATION (HT) 0A | 0000000A | LINE FEED (LF) 0B | 0000000B | LINE TABULATION (VT) 0C | 0000000C | FORM FEED (FF) 0D | 0000000D | CARRIAGE RETURN (CR) 0E | 0000000E | SHIFT OUT (SO) 0F | 0000000F | SHIFT IN (SI) 10 | 00000010 | DATALINK ESCAPE (DLE) 11 | 00000011 | DEVICE CONTROL ONE (DC1) 12 | 00000012 | DEVICE CONTROL TWO (DC2) 13 | 00000013 | DEVICE CONTROL THREE (DC3) 14 | 00000014 | DEVICE CONTROL FOUR (DC4) 15 | 00000015 | NEGATIVE ACKNOWLEDGE (NAK) 16 | 00000016 | SYNCHRONOUS IDLE (SYN) 17 | 00000017 | END OF TRANSMISSION BLOCK (ETB) 18 | 00000018 | CANCEL (CAN) 19 | 00000019 | END OF MEDIUM (EM) 1A | 0000001A | SUBSTITUTE (SUB) 1B | 0000001B | ESCAPE (ESC) 1C | 0000001C | FILE SEPARATOR (IS4) 1D | 0000001D | GROUP SEPARATOR (IS3) 1E | 0000001E | RECORD SEPARATOR (IS2) 1F | 0000001F | UNIT SEPARATOR (IS1) 20 | 00000020 | SPACE 24 | 00000024 | DOLLAR SIGN 25 | 00000025 | PERCENT SIGN 27 | 00000027 | APOSTROPHE 28 | 00000028 | LEFT PARENTHESIS 29 | 00000029 | RIGHT PARENTHESIS 2A | 0000002A | ASTERISK 2B | 0000002B | PLUS SIGN 2C | 0000002C | COMMA 2D | 0000002D | HYPHEN-MINUS 2E | 0000002E | FULL STOP 2F | 0000002F | SOLIDUS 30 | 00000030 | DIGIT ZERO 31 | 00000031 | DIGIT ONE 32 | 00000032 | DIGIT TWO 33 | 00000033 | DIGIT THREE 34 | 00000034 | DIGIT FOUR 35 | 00000035 | DIGIT FIVE 36 | 00000036 | DIGIT SIX 37 | 00000037 | DIGIT SEVEN 38 | 00000038 | DIGIT EIGHT 39 | 00000039 | DIGIT NINE 3A | 0000003A | COLON 3B | 0000003B | SEMICOLON 3C | 0000003C | LESS-THAN SIGN 3D | 0000003D | EQUALS SIGN 3E | 0000003E | GREATER-THAN SIGN 41 | 00000041 | LATIN CAPITAL LETTER A 42 | 00000042 | LATIN CAPITAL LETTER B 43 | 00000043 | LATIN CAPITAL LETTER C 44 | 00000044 | LATIN CAPITAL LETTER D 45 | 00000045 | LATIN CAPITAL LETTER E 46 | 00000046 | LATIN CAPITAL LETTER F 47 | 00000047 | LATIN CAPITAL LETTER G 48 | 00000048 | LATIN CAPITAL LETTER H 49 | 00000049 | LATIN CAPITAL LETTER I 4A | 0000004A | LATIN CAPITAL LETTER J 4B | 0000004B | LATIN CAPITAL LETTER K 4C | 0000004C | LATIN CAPITAL LETTER L 4D | 0000004D | LATIN CAPITAL LETTER M 4E | 0000004E | LATIN CAPITAL LETTER N 4F | 0000004F | LATIN CAPITAL LETTER O 50 | 00000050 | LATIN CAPITAL LETTER P 51 | 00000051 | LATIN CAPITAL LETTER Q 52 | 00000052 | LATIN CAPITAL LETTER R 53 | 00000053 | LATIN CAPITAL LETTER S 54 | 00000054 | LATIN CAPITAL LETTER T 55 | 00000055 | LATIN CAPITAL LETTER U 56 | 00000056 | LATIN CAPITAL LETTER V 57 | 00000057 | LATIN CAPITAL LETTER W 58 | 00000058 | LATIN CAPITAL LETTER X 59 | 00000059 | LATIN CAPITAL LETTER Y 5A | 0000005A | LATIN CAPITAL LETTER Z 5B | 0000005B | LEFT SQUARE BRACKET 5D | 0000005D | RIGHT SQUARE BRACKET 61 | 00000061 | LATIN SMALL LETTER A 62 | 00000062 | LATIN SMALL LETTER B 63 | 00000063 | LATIN SMALL LETTER C 64 | 00000064 | LATIN SMALL LETTER D 65 | 00000065 | LATIN SMALL LETTER E 66 | 00000066 | LATIN SMALL LETTER F 67 | 00000067 | LATIN SMALL LETTER G 68 | 00000068 | LATIN SMALL LETTER H 69 | 00000069 | LATIN SMALL LETTER I 6A | 0000006A | LATIN SMALL LETTER J 6B | 0000006B | LATIN SMALL LETTER K 6C | 0000006C | LATIN SMALL LETTER L 6D | 0000006D | LATIN SMALL LETTER M 6E | 0000006E | LATIN SMALL LETTER N 6F | 0000006F | LATIN SMALL LETTER O 70 | 00000070 | LATIN SMALL LETTER P 71 | 00000071 | LATIN SMALL LETTER Q 72 | 00000072 | LATIN SMALL LETTER R 73 | 00000073 | LATIN SMALL LETTER S 74 | 00000074 | LATIN SMALL LETTER T 75 | 00000075 | LATIN SMALL LETTER U 76 | 00000076 | LATIN SMALL LETTER V 77 | 00000077 | LATIN SMALL LETTER W 78 | 00000078 | LATIN SMALL LETTER X 79 | 00000079 | LATIN SMALL LETTER Y 7A | 0000007A | LATIN SMALL LETTER Z 7C | 0000007C | VERTICAL LINE 7F | 0000007F | DELETE (DEL) AUTHOR
Copyright (C) 2002-2009, Guido Flohr <guido@imperia.net>, all rights reserved. See the source code for details. This software is contributed to the Perl community by Imperia (<http://www.imperia.net/>). SEE ALSO
Locale::RecodeData(3), Locale::Recode(3), perl(1) POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 863: =cut found outside a pod block. Skipping to next block. perl v5.16.3 2014-06-10 Locale::RecodeData::INIS(3)
All times are GMT -4. The time now is 05:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy