Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Awk: group multiple fields from different records Post 303019797 by RudiC on Friday 6th of July 2018 05:00:35 PM
Old 07-06-2018
You can "sharpen" or "narrow down" the regex to avoid false positive matches like
Code:
awk -F\| '
        {if (!(a[$1] ~ "(^|;)" $2 "(;|$)")) a[$1] = a[$1] DL[$1] $2
         if (!(b[$1] ~ "(^|;)" $3 "(;|$)")) b[$1] = b[$1] DL[$1] $3
         DL[$1] = ";"
        }
END     {for (i in a)   {print i, a[i], b[i]
                        }
        }
' OFS="|"  file

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

AWK ??-print for fields within records in a file

Hello all, Would appreciate if someone can help me out on the following requirement. INPUT FILE: -------------------------- TPS REPORT abc def ghi jkl mon pqr stu vrs lll END OF TPS REPORT TPS REPORT field1 field2 field3 field4 field5 field6 (8 Replies)
Discussion started by: hyennah
8 Replies

2. Infrastructure Monitoring

Processing records as group - awk

I have a file has following records policy glb id 1233 name Permit ping from "One" to "Second" "Address1" "Any" "ICMP-ANY" permit policy id 999251 service "snmp-udp" exit policy glb id 1234 name Permit telnet from "One" to "Second" "Address2" "Any" "TCP-ANY" permit policy id 1234... (3 Replies)
Discussion started by: baskar
3 Replies

3. Shell Programming and Scripting

how to parse with awk (using different fields), then group by a field?

When parsing multiple fields in a file using AWK, how do you group by one of the fields and parse by delimiters? to clarify If a file had tom | 223-2222-4444 , randofield ivan | 123-2422-4444 , random filed ... | and , are the delimiters ... How would you group by the social security... (4 Replies)
Discussion started by: Josef_Stalin
4 Replies

4. UNIX for Dummies Questions & Answers

keeping last record among group of records with common fields (awk)

input: ref.1;rack.1;1 #group1 ref.1;rack.1;2 #group1 ref.1;rack.2;1 #group2 ref.2;rack.3;1 #group3 ref.2;rack.3;2 #group3 ref.2;rack.3;3 #group3 Among records from same group (i.e. with same 1st and 2nd field - separated by ";"), I would need to keep the last record... (5 Replies)
Discussion started by: beca123456
5 Replies

5. Shell Programming and Scripting

awk gsub multiple fields

Hi, I am trying to execute this line awk -F ";" -v OFS=";" '{gsub(/\./,",",$6); print}' FILE but for multiple fields $6 $7 $8 Do you have a suggstion? Tried: awk -F ";" -v OFS="";"" "function GSUB( F ) {gsub(/\./,\",\",$F); print} { GSUB( 6 ); GSUB( 7 ); GSUB( 8 ) } 1"... (2 Replies)
Discussion started by: nakaedu
2 Replies

6. Shell Programming and Scripting

awk multiple fields separators

Can you please help me with this .... Input File share "FTPTransfer" "/v31_fs01/root/FTP-Transfer" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "Test" "/v31_fs01/root/Test" umask=022 maxusr=4294967295 netbios=NJ09FIL530 share "ENR California" "/v31_fs01/root/ENR California"... (14 Replies)
Discussion started by: greycells
14 Replies

7. UNIX for Dummies Questions & Answers

Make all records with the same number of fields (awk)

Hi, input: AA|BB|CC DD|EE FF what I am trying to get: AA|BB|CC DD|EE| FF|| I tried to create first an UDF for printing repeats, but I think I have an issue with my END section or my array: function repeat(str, n, rep, i) { for(i=1 ;i<n;i++) rep=rep str return rep } ... (6 Replies)
Discussion started by: beca123456
6 Replies

8. Shell Programming and Scripting

Shell Script to Group by Based on Multiple Fields in a file

Hi, I want to know if there is any simple approach to SUM a field based on group by of different fields for e.g. file1.txt contains below data 20160622|XXX1||50.00||50.00|MONEY|Plan1| 20160622|XXX1||100.00||100.00|MONEY|Plan1| 20160623|XXX1||25.00||25.00|MONEY|Plan1|... (3 Replies)
Discussion started by: cnu_theprince
3 Replies

9. Shell Programming and Scripting

Print multiple fields with awk

so its common knowledge one can print multiple fields with simple commands like this: echo 12 44 45 552 24 | awk '{print $1,$4,$3}' but suppose i want to avoid specifying the "$" symbol. is that possible? can something like this be done: echo 12 44 45 552 24 | awk '{print $(1,4,3)}' ... (9 Replies)
Discussion started by: SkySmart
9 Replies

10. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies
PANGO-VIEW(1)							   User Commands						     PANGO-VIEW(1)

NAME
pango-view - Pango text viewer DESCRIPTION
Usage: pango-view [OPTION...] - FILE Help Options: -h, --help Show help options --help-all Show all help options --help-cairo Options understood by the cairo backend Cairo backend options: --annotate=1 or 2 Annotate the output Application Options: --no-auto-dir No layout direction according to contents --backend=cairo/xft/ft2/x Pango backend to use for rendering (default: cairo) --background=red/#rrggbb/#rrggbbaa/transparent Set the background color -q, --no-display Do not display (just write to file or whatever) --dpi=number Set the resolution --align=left/center/right Text alignment --ellipsize=start/middle/end Ellipsization mode --font=description Set the font description --foreground=red/#rrggbb/#rrggbbaa Set the text color --gravity=south/east/north/west/auto Base gravity: glyph rotation --gravity-hint=natural/strong/line Gravity hint --header Display the options in the output --height=+points/-numlines Height in points (positive) or number of lines (negative) for ellipsizing --hinting=none/auto/full Hinting style --indent=points Width in points to indent paragraphs --justify Align paragraph lines to be justified --language=en_US/etc Language to use for font selection --margin=pixels Set the margin on the output in pixels --markup Interpret text as Pango markup -o, --output=file Save rendered image to output file --pangorc=file pangorc file to use (default is ./pangorc) --pixels Use pixel units instead of points (sets dpi to 72) --rtl Set base direction to right-to-left --rotate=degrees Angle at which to rotate results -n, --runs=integer Run Pango layout engine this many times --single-par Enable single-paragraph mode -t, --text=string Text to display (instead of a file) --version Show version numbers --waterfall Create a waterfall display -w, --width=points Width in points to which to wrap lines or ellipsize --wrap=word/char/word-char Text wrapping mode (needs a width to be set) Pango module interface version: 1.6.0 pango-view (pango) 1.28.0 March 2010 PANGO-VIEW(1)
All times are GMT -4. The time now is 08:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy