Sponsored Content
Top Forums Shell Programming and Scripting Print values within groups of lines with awk Post 302958611 by Ophiuchus on Friday 23rd of October 2015 06:42:28 PM
Old 10-23-2015
Thanks MadeInGermany, your're right.

I've added the END and print when each block begins and at the END and works now and adding the function as you sugested.

Code:
awk '
 function prt(){if (NR>1) {print a"|"b"|"c"|"d"|"e; a="";b="";c="";d="";e=""}}
 /ZYX/{prt()}
         /A/ {a=$3}
         /B/ {b=$3}
         /C/ {c=$3}
         /D/ {d=$3}
         /E/ {e=$3}
 END{prt()}' file.txt

Thanks again.

Best regards
This User Gave Thanks to Ophiuchus For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print a key with its all values using awk/others

input COL1 a1 b1 c1 d1 e1 f1 C1 10 10 10 100 100 1000 C2 20 20 200 200 200 2000 output C1 a1 10 1 C1 b1 10 1 C1 c1 10 1 C1 d1 100 2 C1 e1 100 2 C1 f1 1000 3 C2 ... (12 Replies)
Discussion started by: ruby_sgp
12 Replies

2. Shell Programming and Scripting

awk- looping through groups of lines

Hello, I'm working with a file that has three columns. The first one represents a certain channel and the third one a timestamp (second one is not important). Example input is as follows: 2513 12 10.771 2513 13 10.771 2513 14 10.771 2513 15 10.771 2644 8 10.771 ... (6 Replies)
Discussion started by: acsg
6 Replies

3. UNIX for Dummies Questions & Answers

Only print lines with 3 numeric values

Hey guys & gals, I am hoping for some advice on a sed or awk command that will allow to only print lines from a file that contain 3 numeric values. From previous searches here I saw that ygemici used the sed command to remove lines containing more than 3 numeric values ; however how... (3 Replies)
Discussion started by: TAPE
3 Replies

4. Shell Programming and Scripting

Print lines containing same values in a group

Hi, I have a table like this: Name A1 A2 A3 B1 B2 B3 111 abc abc abc cbc cbc cbc 222 acv acv n_n bbc bbc bbc 333 bvv bvv bvv cBx ccx ccx 444 ttk ttk ttk kke kke kke 555 mcr mcr mcr mcr mcr mcr The 1st column is just names... (3 Replies)
Discussion started by: polsum
3 Replies

5. Shell Programming and Scripting

How to print in awk matching $1 values ,to $1,$4 example given.?

Hi Experts, I am trying to get the output from a matching pattern but unable to construct the awk command: file : aa bb cc 11 dd aa cc 33 cc 22 45 68 aa 33 44 44 dd aa cc 37 aa 33 44 67 I want the output to be : ( if $1 match to "aa" start of the line,then print $4 of that line, and... (3 Replies)
Discussion started by: rveri
3 Replies

6. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

awk print values between consecutive lines

I have a file in below format: file01.txt TERM TERM TERM ABC 12315 68.53 12042013 165144 ABC 12315 62.12 12042013 165145 ABC 12315 122.36 12052013 165146 ABC 12315 582.18 12052013 165147 ABC 12316 2.36 12052013 165141 ABC 12316 ... (8 Replies)
Discussion started by: alex2005
8 Replies

8. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

9. Shell Programming and Scripting

How to print lines that have values in certain columns ?

Hi, everyone I have a dataset like this: A B C D A C C D E F G H F D K Y X A K K C Gsome of columns have no values in each line. I want to print all lines that have 1/2/3/4 values, export separately to four files. What I expected is like this: file1 Y file 2 A C X Afile 3... (3 Replies)
Discussion started by: nengcheng
3 Replies

10. UNIX for Beginners Questions & Answers

Print lines based upon unique values in Nth field

For some reason I am having difficulty performing what should be a fairly easy task. I would like to print lines of a file that have a unique value in the first field. For example, I have a large data-set with the following excerpt: PS003,001 MZMWR/ L-DWD// * PS003,001... (4 Replies)
Discussion started by: jvoot
4 Replies
sccs-prt(1)							   User Commands						       sccs-prt(1)

NAME
sccs-prt, prt - display delta table information from an SCCS file SYNOPSIS
/usr/ccs/bin/prt [-abdefistu] [-cdate-time] [-rdate-time] [-ysid] s.filename... DESCRIPTION
prt prints selected portions of an SCCS file. By default, it prints the delta table (version log). If a directory name is used in place of the s.filename argument, the prt command applies to all s.files in that directory. Unreadable s.files produce an error; processing continues with the next file (if any). The use of `-' as the s.filename argument indicates that the names of files are to be read from the standard input, one s.file per line. OPTIONS
If any option other than -y, -c, or -r is supplied, the name of each file being processed (preceded by one NEWLINE and followed by two NEW- LINE characters) appears above its contents. If none of the -u, -f, -t, or -b options are used, -d is assumed. -s, -i are mutually exclusive, as are -c and -r. -a Display log entries for all deltas, including those marked as removed. -b Print the body of the s.file. -d Print delta table entries. This is the default. -e Everything. This option implies -d, -i, -u, -f, and -t. -f Print the flags of each named s.file. -i Print the serial numbers of included, excluded, and ignored deltas. -s Print only the first line of the delta table entries; that is, only up to the statistics. -t Print the descriptive text contained in the s.file. -u Print the user-names and/or numerical group IDs of users allowed to make deltas. -cdate-time Exclude delta table entries that are specified cutoff date and time. Each entry is printed as a single line, preceded by the name of the SCCS file. This format (also produced by -r , and -y) makes it easy to sort multiple delta tables in chronological order. When both -y and -c, or -y and -r are supplied, prt stops printing when the first of the two condi- tions is met. -rdate-time Exclude delta table entries that are newer than the specified cutoff date and time. -ysid Exclude delta table entries made prior to the SID specified. If no delta in the table has the specified SID, the entire table is printed. If no SID is specified, the most recent delta is printed. USAGE
Output Format The following format is used to print those portions of the s.file that are specified by the various options. o NEWLINE o Type of delta (D or R) o SPACE o SCCS delta ID (SID) o TAB o Date and time of creation in the form: yy/mm/dd hh/mm/ss o SPACE o Username the delta's creator o TAB o Serial number of the delta o SPACE o Predecessor delta's serial number o TAB o Line-by-line change statistics in the form: inserted/deleted/unchanged o NEWLINE o List of included deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of excluded deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of ignored deltas, followed by a NEWLINE (only if there were any such deltas and the -i options was used) o List of modification requests (MRs), followed by a NEWLINE (only if any MR numbers were supplied). o Lines of the delta commentary (if any), followed by a NEWLINE. EXAMPLES
Example 1: Examples of prt. The following command: example% /usr/ccs/bin/prt -y program.c produces a one-line display of the delta table entry for the most recent version: s.program.c: D 1.6 88/07/06 21:39:39 username 5 4 00159/00080/00636... ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsprot | +-----------------------------+-----------------------------+ SEE ALSO
sccs(1), sccs-cdc(1), sccs-delta(1), sccs-get(1), sccs-help(1), sccs-prs(1), sccs-sact(1), sccs-sccsdiff(1), what(1), sccsfile(4), attributes(5) DIAGNOSTICS
Use the SCCS help command for explanations (see sccs-help(1)). SunOS 5.10 5 Oct 1990 sccs-prt(1)
All times are GMT -4. The time now is 08:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy