Sponsored Content
Full Discussion: Help with regex construction
Top Forums Shell Programming and Scripting Help with regex construction Post 302456027 by euval on Thursday 23rd of September 2010 04:43:52 AM
Old 09-23-2010
Help with regex construction

I am trying to construct a regular expression that will filter a log file containing the following table:
Code:
  aP      [1,P1]
  mP      [3,P2] [4,P2(1)]
 mC,mI    [5,C2]
  oP      [16,P222] [17,P222(1)] [18,P2(1)2(1)2] [19,P2(1)2(1)2(1)]
  oC      [21,C222] [20,C222(1)]
  oF      [22,F222]
  oI      [23,I222] [24,I2(1)2(1)2(1)]
  tP      [75,P4] [76,P4(1)] [77,P4(2)] [78,P4(3)] [89,P422] [90,P42(1)2]
          [91,P4(1)22] [92,P4(1)2(1)2] [93,P4(2)22] [94,P4(2)2(1)2]
          [95,P4(3)22] [96,P4(3)2(1)2]
  tI      [79,I4] [80,I4(1)] [97,I422] [98,I4(1)22]
  hP      [143,P3] [144,P3(1)] [145,P3(2)] [149,P312] [150,P321] [151,P3(1)12]
          [152,P3(1)21] [153,P3(2)12] [154,P3(2)21] [168,P6] [169,P6(1)]
          [170,P6(5)] [171,P6(2)] [172,P6(4)] [173,P6(3)] [177,P622]
          [178,P6(1)22] [179,P6(5)22] [180,P6(2)22] [181,P6(4)22] [182,P6(3)22]
  hR      [146,R3] [155,R32]
  cP      [195,P23] [198,P2(1)3] [207,P432] [208,P4(2)32] [212,P4(3)32]
          [213,P4(1)32]
  cF      [196,F23] [209,F432] [210,F4(1)32]
  cI      [197,I23] [199,I2(1)3] [211,I432] [214,I4(1)32]

This basically consists of a list (in no particular order) of two strings, one consisting of number and the other a mixture of numbers, letters and (). The two strings are separated by a comma and are enclosed within [ ].

What I want to have is an awk/sed one-liner that will output the second string when the number string is specified. For example, if I search with 155 this will spit out R32.

At the moment I have this monstrosity:
Code:
awk /155/ | awk 'BEGIN{FS=" "}{for (i=1; i<=NF; i++) print $i}' | awk /155/ | cut -d "," -f 2 | cut -d "]" -f 1

which works for 155, but I cannot use it for 1, for example, where P1 would be the correct output.

Any help much appreciated!
 

7 More Discussions You Might Find Interesting

1. Cybersecurity

Password Construction

Could someone please help, I am new to unix and I am trying to do the following: o Each password must have at least eight characters. Only the first eight characters are significant. PASSLENGTH is found in /etc/default/passwd and is set to 6. ... (1 Reply)
Discussion started by: tumbikikani
1 Replies

2. Shell Programming and Scripting

Matrix construction

Hi experts How to construct a rectangular matrix for a text file with 6012 rows and 2221 columns. Thank You (1 Reply)
Discussion started by: riyabio
1 Replies

3. Shell Programming and Scripting

Matrix construction

Hi I have to construct a rectangular matrix with 6012 rows and 2221 columns. Here the rows and columns were given by alphanumeric ids in a file named row.txt and column.txt respectively. with this row nd column ids I have to construct a matrix ie 6012*2221 and compare the column ids with... (0 Replies)
Discussion started by: riyabio
0 Replies

4. Shell Programming and Scripting

case construction for basic Arithmetics calculation

the scrip (q4.sh) should perform the following calcuation (+, -, / and *) it should be used like this: q4.sh number1 operation number2 I wrote it already but the "*" does not work. #!/bin/bash #Date: 2010.10.19 # un script qui utilisera une instruction case pour effectuer des opérations... (6 Replies)
Discussion started by: flash80
6 Replies

5. Web Development

Website construction nowaday!

Hello, Actually I am not sure how to ask this question, which is about the technique advance on website construction/design. Compared with HTML/CSS, which ones are the most popular for website construction? My colleague recommends Drupal for Linux platform. Any other? Thanks! Yifang (4 Replies)
Discussion started by: yifangt
4 Replies

6. Shell Programming and Scripting

Grep command construction

Hi, I have an array variable "arr" that reads string from a file "vari.txt". Thus, the array will be of variable length depending how many entries are present in "vari.txt" I use a for loop to traverse through the array. However, i need a grep command to grep for a file "output.txt" and... (3 Replies)
Discussion started by: mohtashims
3 Replies

7. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 03:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy