Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help in printing records where there is a 'header' in the first record ??? Post 303010165 by newbie_01 on Thursday 28th of December 2017 01:01:17 AM
Old 12-28-2017
Help in printing records where there is a 'header' in the first record ???

Hi,

I have a backup report that unfortunately has some kind of hanging indent thing where the first line contains one column more than the others

I managed to get the output that I wanted using awk, but just wanting to know if there is short way of doing it using the same awk

Below is what I have so far:

This is the content of the report so far, hopefully it doesn't change. I change the information to not show the real information but the format is more or less correct.

Code:
$: cat /tmp/x.txt
Some text here
Some header information here
Some header information here
------- ------------- ------- ------------- -------------------- --------- ----
xxx2ns666-pr-non-xxxTEST xx_tmp_abcq xxx2ns111-dr-01h-xxxTEST vol_abcp_zz xxx1ns999_vol_abcp_zz_yy.1 online RO
                         xx_tmp_abct xxx2ns111-dr-01h-xxxTEST vol_abcp_zz xxx1ns999_vol_abcp_zz_yy.16 online RO
                         xx_tmp_defd xxx2ns111-dr-01h-xxxTEST vol_defp_zz xxx1ns999_vol_defp_zz_yy.16 online RO
                         xx_tmp_ghiq xxx2ns111-dr-01h-xxxTEST vol_ghip_zz xxx1ns999_vol_ghip_zz_yy.16 online RO
                         xx_tmp_ghit xxx2ns111-dr-01h-xxxTEST vol_ghip_zz xxx1ns999_vol_ghip_zz_yy.17 online RO
5 entries were displayed.

Below is my long very newbie awk command Smilie

Code:
cat /tmp/x.txt | grep xx_tmp | grep -v "^$" | awk 'NR==1 { print $2 " " $3 " " $4 " " $5 " " $6 " " $7 } NR>1 { print $1 " " $2 " " $3 " " $4 " " $5 " " $6 }'

xx_tmp_abcq xxx2ns111-dr-01h-xxxTEST vol_abcp_zz xxx1ns999_vol_abcp_zz_yy.1 online RO
xx_tmp_abct xxx2ns111-dr-01h-xxxTEST vol_abcp_zz xxx1ns999_vol_abcp_zz_yy.16 online RO
xx_tmp_defd xxx2ns111-dr-01h-xxxTEST vol_defp_zz xxx1ns999_vol_defp_zz_yy.16 online RO
xx_tmp_ghiq xxx2ns111-dr-01h-xxxTEST vol_ghip_zz xxx1ns999_vol_ghip_zz_yy.16 online RO
xx_tmp_ghit xxx2ns111-dr-01h-xxxTEST vol_ghip_zz xxx1ns999_vol_ghip_zz_yy.17 online RO

The grep -v "^$" is just a sanity thing. Is there a shorter way that does the same?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to extract duplicate records with associated header record

All, I have a task to search through several hundred files and extract duplicate detail records and keep them grouped with their header record. If no duplicate detail record exists, don't pull the header. For example, an input file could look like this: input.txt HA D1 D2 D2 D3 D4 D4... (17 Replies)
Discussion started by: run_eim
17 Replies

2. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

3. Shell Programming and Scripting

awk script to update header record

I am using HP UX and think this may be done with awk but bot sure. I have a file with a several header records and undeneath many detail records I need to put in the header record the number of detail records above this header record and number of detail records below this header record Header... (5 Replies)
Discussion started by: klut
5 Replies

4. UNIX for Dummies Questions & Answers

change order of fields in header record

Hello, after 9 months of archiving 1000 files, now, i need to change the order of fields in the header record. some very large, space padded files. HEADERCAS05212008D0210DOMEST01(spacepadded to record length 210) must now be 05212008HEADERCASD0210DOMEST01(spacepadded to record length 210) ... (1 Reply)
Discussion started by: JohnMario
1 Replies

5. Shell Programming and Scripting

Skip parsing the header record - Awk

Guys.... Got a scenario in which I need to skip parsing the header record while I do an awk. Does awk has the flexibility to accomplish this?. If so, how do we do this?. Thanks !!! -Anduzzi :) (2 Replies)
Discussion started by: anduzzi
2 Replies

6. Shell Programming and Scripting

Insertion of Header record

A header record is to be inserted in the begining of a flat file without using extra file or new file. It should be inserted into same file. Advace thanks for all help... (7 Replies)
Discussion started by: shreekrishnagd
7 Replies

7. UNIX for Dummies Questions & Answers

pull date from header and append to all records

I did some searches, but couldn't really find what I'm looking for. I have a file formatted as below: BOF ABC CO - XYZ COMM DATA OF 07/05/2011 EBA00000001 sdfa rtyus uyml EBB00000001 54682 984w3 EBA00000002 mkiyuasdf 98234 I want to pull the date from the header record and add it... (4 Replies)
Discussion started by: keeferb
4 Replies

8. Shell Programming and Scripting

Specific Header after every 30 records

Hi All, I have got a requirement. I have a source file, EMPFULL.txt and I need to split the data for every 30 records and place a Typical Header as below with system and page number too. 2012.01.03 Employee Dept Report 1... (6 Replies)
Discussion started by: srk409
6 Replies

9. Shell Programming and Scripting

Approach on Header record

All, I currently have a requirement to fetch a Date value from a table. And then insert a Header record into a file along with that date value. ex: echo "HDR"" "`date +%Y%j` `date +%Y%m%d` In the above example I used julian date and standard date using Current Date. But the requirement... (0 Replies)
Discussion started by: cmaroju
0 Replies

10. Shell Programming and Scripting

Copy header values into records

I'm using a shell script to manipulate a data file. I have a large file with two sets of data samples (tracking memory consumption) taken over a long period of time, so I have many samples. The problem is that all the data is in the same file so that each sample contains two sets of data.... (2 Replies)
Discussion started by: abercrom
2 Replies
MESSAGES(3)						  libbash messages Library Manual					       MESSAGES(3)

NAME
messages -- libbash library that implements a set of functions to print standard status messages SYNOPSIS
printOK [indent] printFAIL [indent] printNA [indent] printATTN [indent] printWAIT [indent] DESCRIPTION
General messages is a collection of functions to print standard status messages - those [ OK ] and [FAIL] messages you see during Linux boot process. The function list: printOK Prints a standard [ OK ] message (green) printFAIL Prints a standard [FAIL] message (red) printNA Prints a standard [ N/A] message (yellow) printATTN Prints a standard [ATTN] message (yellow) printWAIT Prints a standard [WAIT] message (yellow) Detailed interface description follows. indent Column to move to before printing. Default indent is calculated as TTY_WIDTH-10. If current tty width can not be determined (for example, in case of serial console), it defaults to 80, so default indent is 80-10=10 FUNCTIONS DESCRIPTIONS
printOK [indent] Prints a standard [ OK ] message (green) printFAIL [indent] Prints a standard [FAIL] message (red) printNA [indent] Prints a standard [ N/A] message (yellow) printATTN [indent] Prints a standard [ATTN] message (yellow) printWAIT [indent] Prints a standard [WAIT] message (yellow) EXAMPLES
Run a program named MyProg, and report it's success or failure: echo -n 'Running MyProg...' printWAIT if MyProg ; then printOK else printFAIL fi AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 10:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy