Sponsored Content
Full Discussion: Reformatting Data in AWK
Top Forums Shell Programming and Scripting Reformatting Data in AWK Post 302297009 by sda_rr on Thursday 12th of March 2009 10:10:17 AM
Old 03-12-2009
Reformatting in AWK

Franklin52,

Apologies for not sending the desired output format. I also noticed an error in the original dataset which could have been very misleading. Please find a corrected dataset below followed by the desired output format.

regards,

sda_rr


Code:
SET LOCATION ANGLE1 ANGLE2 TYPE
D2 probe101 probe201 probe301 probe401
probe501 probe102 probe202 probe302 probe402
probe502 probe103 probe203 probe303 probe403
probe503 probe104 probe204 probe304 probe404
probe504 probe105 probe205 probe305 probe405
probe505 probe106 probe206 probe306 probe406
probe506 probe107 probe207 probe307 probe407
probe507 probe108 probe208 probe308 probe408
probe508 probe109 probe209 probe309 probe409
probe509 probe110 probe210 probe310 probe410
probe510 cprobe101 cprobe201 cprobe301 cprobe401
1 50 5 0 1
16 1.00E+05 1.50E+05 1.00E+05 1.50E+05
1.13E+05 1.13E+05 1.13E+05 7.50E+04 1.13E+05
8.44E+04 8.44E+04 8.44E+04 5.63E+04 8.44E+04
6.33E+04 6.33E+04 6.33E+04 4.22E+04 6.33E+04
4.75E+04 4.75E+04 4.75E+04 3.16E+04 4.75E+04
3.56E+04 3.56E+04 3.56E+04 2.37E+04 3.56E+04
2.67E+04 2.67E+04 2.67E+04 1.78E+04 2.67E+04
2.00E+04 2.00E+04 2.00E+04 1.33E+04 2.00E+04
1.50E+04 1.50E+04 1.50E+04 1.00E+04 1.50E+04
1.13E+04 1.13E+04 1.13E+04 7.51E+03 1.13E+04
8.45E+03 8.45E+03 8.45E+03 5.63E+03 8.45E+03
2 100 10 0 2
1.18E+05 1.18E+05 1.18E+05 7.88E+04 1.18E+05
8.86E+04 8.86E+04 8.86E+04 5.91E+04 8.86E+04
6.64E+04 6.64E+04 6.64E+04 4.43E+04 6.64E+04
4.98E+04 4.98E+04 4.98E+04 3.32E+04 4.98E+04
3.74E+04 3.74E+04 3.74E+04 2.49E+04 3.74E+04
2.80E+04 2.80E+04 2.80E+04 1.87E+04 2.80E+04
2.10E+04 2.10E+04 2.10E+04 1.40E+04 2.10E+04
1.58E+04 1.58E+04 1.58E+04 1.05E+04 1.58E+04
1.18E+04 1.18E+04 1.18E+04 7.88E+03 1.18E+04
8.87E+03 8.87E+03 8.87E+03 5.91E+03 8.87E+03
2.10E+00 1.05E+02 1.05E+01 0.00E+00 2.10E+00
6 300 30 0 6
1.20E+05 1.20E+05 1.20E+05 8.03E+04 1.20E+05
9.04E+04 9.04E+04 9.04E+04 6.02E+04 9.04E+04
6.78E+04 6.78E+04 6.78E+04 4.52E+04 6.78E+04
5.08E+04 5.08E+04 5.08E+04 3.39E+04 5.08E+04
3.81E+04 3.81E+04 3.81E+04 2.54E+04 3.81E+04
2.86E+04 2.86E+04 2.86E+04 1.91E+04 2.86E+04
2.14E+04 2.14E+04 2.14E+04 1.43E+04 2.14E+04
1.61E+04 1.61E+04 1.61E+04 1.07E+04 1.61E+04
1.21E+04 1.21E+04 1.21E+04 8.04E+03 1.21E+04
9.05E+03 9.05E+03 9.05E+03 6.03E+03 9.05E+03
2.14E+00 1.07E+02 1.07E+01 0.00E+00 2.14E+00

General Output Format
Code:
SET LOCATION ANGLE1 ANGLE2 TYPE probe101 probe102 probe103 probe104 probe105 probe106 probe107 probe108 probennn
1 50 5 0 1 1.00E+05 1.13E+05 8.44E+04 6.33E+04 4.75E+04 3.56E+04 2.67E+04 2.00E+04 ...
2 100 10 0 2 1.18E+05 8.86E+04 6.64E+04 4.98E+04 3.74E+04 2.80E+04 2.10E+04 1.58E+04 ...
6 300 30 0 6 1.20E+05 9.04E+04 6.78E+04 5.08E+04 3.81E+04 2.86E+04 2.14E+04 1.61E+04 ...


Last edited by radoulov; 03-12-2009 at 12:40 PM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

reformatting a floppy!

i am trying to reformat a floppy i am using solaris 9 when i run this: rmformat -F quick /vol/dev/aliases/floppy0 it tells me that it cannot perform the operation on a mounted device. how do i unmount the device and format the floppy? (1 Reply)
Discussion started by: rmuhammad
1 Replies

2. Shell Programming and Scripting

awk multiple file reformatting

I hopefully have a simple request - I need to process multiple files reformatting the output based on tags at the beginning of each line. So the data for the new 3 lines of the output file are in the HDR line and then the details are in the DTL tagged lines. for ifile in $indir do echo... (1 Reply)
Discussion started by: jason_v_brown
1 Replies

3. Shell Programming and Scripting

reformatting xml file, sed or awk I think (possibly perl)

I have some xml files that cannot be read using a standard parser, or I am using the wrong parser. The issues seems to be spaces in some of the tags. Here is a sample,<UgUn 2 > <Un> -0.426753 </Un> </UgUn>The parser isn't able to find the number 2, so that information is lost, etc. It seems... (16 Replies)
Discussion started by: LMHmedchem
16 Replies

4. UNIX for Dummies Questions & Answers

Date reformatting

I have a file with temperature measurements: Loc1,20090102,71.55 Loc1,20090103,71.65 Loc1,20090104,71.55 Loc1,20090105,71.54 Loc1,20090106,71.54 However, to load this into a database I would like to reformat the dates (column 2) from the yyyymmdd format to the yyyy-mm-dd format. I have... (2 Replies)
Discussion started by: figaro
2 Replies

5. UNIX for Dummies Questions & Answers

Date reformatting

I have been reformatting dates from a data file to make them mysql compliant. 31-10-2011 Loc1 1-11-2011 Loc2 The first can be captured by this: sed -i '' -e "s#\(..\)-\(..\)-\(....\)#\3-\2-\1#" data.txt and leads to: 2011-10-31 Loc1 The second line is captured as follows: sed -i... (2 Replies)
Discussion started by: figaro
2 Replies

6. Shell Programming and Scripting

Reformatting data in matrix form

Hi, Some assistance with respect to the following problem will be very helpful. I want to reformat my dataset in the following manner for subsequent analysis. I have first column values (which repeat for each value of 2nd column) which are names, the second column specifies position ad the... (1 Reply)
Discussion started by: newbie83
1 Replies

7. Shell Programming and Scripting

Help with parsing data with awk , eliminating unwanted data

Experts , Below is the data: --- Physical volumes --- PV Name /dev/dsk/c1t2d0 VG Name /dev/vg00 PV Status available Allocatable yes VGDA 2 Cur LV 8 PE Size (Mbytes) 8 Total PE 4350 Free PE 2036 Allocated PE 2314 Stale PE 0 IO Timeout (Seconds) default --- Physical volumes ---... (5 Replies)
Discussion started by: rveri
5 Replies

8. Shell Programming and Scripting

awk help reformatting badly formatted time field

I need help reformatting an input file with spaces in the time field (4th field). I want the field to look like “hh:mm” with appropriate embedded zeros, but instead it has “h :m “ if the hour and/or minute are single character. I'm pretty new to scripting and this is beyond me. Any help would... (4 Replies)
Discussion started by: lisep
4 Replies

9. Shell Programming and Scripting

awk --> math-operation in data-record and joining with second file data

Hi! I have a pretty complex job - at least for me! i have two csv-files with meassurement-data: fileA ...... (2 Replies)
Discussion started by: IMPe
2 Replies

10. Shell Programming and Scripting

Help reformatting column

Hello UNIX experts, I'm stumped finding a method to reformat a column. Input file is a two column tab-delimited file. Essentially, for every term that appears in column 2, I would like to summarize whether that term appears for every entry in column 1. In other words, make a header for each term... (2 Replies)
Discussion started by: torchij
2 Replies
HEXDUMP(1)						    BSD General Commands Manual 						HEXDUMP(1)

NAME
hexdump, hd -- ASCII, decimal, hexadecimal, octal dump SYNOPSIS
hexdump [-bcCdovx] [-e format_string] [-f format_file] [-n length] [-s offset] file ... hd [-bcdovx] [-e format_string] [-f format_file] [-n length] [-s offset] file ... DESCRIPTION
The hexdump utility is a filter which displays the specified files, or the standard input, if no files are specified, in a user specified format. The options are as follows: -b One-byte octal display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line. -c One-byte character display. Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space- filled, characters of input data per line. -C Canonical hex+ASCII display. Display the input offset in hexadecimal, followed by sixteen space-separated, two column, hexadecimal bytes, followed by the same sixteen bytes in %_p format enclosed in ``|'' characters. Calling the command hd implies this option. -d Two-byte decimal display. Display the input offset in hexadecimal, followed by eight space-separated, five column, zero-filled, two- byte units of input data, in unsigned decimal, per line. -e format_string Specify a format string to be used for displaying data. -f format_file Specify a file that contains one or more newline separated format strings. Empty lines and lines whose first non-blank character is a hash mark (#) are ignored. -n length Interpret only length bytes of input. -o Two-byte octal display. Display the input offset in hexadecimal, followed by eight space-separated, six column, zero-filled, two byte quantities of input data, in octal, per line. -s offset Skip offset bytes from the beginning of the input. By default, offset is interpreted as a decimal number. With a leading 0x or 0X, offset is interpreted as a hexadecimal number, otherwise, with a leading 0, offset is interpreted as an octal number. Appending the character b, k, or m to offset causes it to be interpreted as a multiple of 512, 1024, or 1048576, respectively. -v Cause hexdump to display all input data. Without the -v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line comprised of a single aster- isk. -x Two-byte hexadecimal display. Display the input offset in hexadecimal, followed by eight, space separated, four column, zero-filled, two-byte quantities of input data, in hexadecimal, per line. For each input file, hexdump sequentially copies the input to standard output, transforming the data according to the format strings speci- fied by the -e and -f options, in the order that they were specified. Formats A format string contains any number of format units, separated by whitespace. A format unit contains up to three items: an iteration count, a byte count, and a format. The iteration count is an optional positive integer, which defaults to one. Each format is applied iteration count times. The byte count is an optional positive integer. If specified it defines the number of bytes to be interpreted by each iteration of the for- mat. If an iteration count and/or a byte count is specified, a single slash must be placed after the iteration count and/or before the byte count to disambiguate them. Any whitespace before or after the slash is ignored. The format is required and must be surrounded by double quote (" ") marks. It is interpreted as a fprintf-style format string (see fprintf(3)), with the following exceptions: o An asterisk (*) may not be used as a field width or precision. o A byte count or field precision is required for each ``s'' conversion character (unlike the fprintf(3) default which prints the entire string if the precision is unspecified). o The conversion characters ``%'', ``h'', ``l'', ``n'', ``p'' and ``q'' are not supported. o The single character escape sequences described in the C standard are supported: NUL <alert character> a <backspace>  <form-feed> f <newline> <carriage return> <tab> <vertical tab> v The hexdump utility also supports the following additional conversion strings: _a[dox] Display the input offset, cumulative across input files, of the next byte to be displayed. The appended characters d, o, and x specify the display base as decimal, octal or hexadecimal respectively. _A[dox] Identical to the _a conversion string except that it is only performed once, when all of the input data has been processed. _c Output characters in the default character set. Nonprinting characters are displayed in three character, zero-padded octal, except for those representable by standard escape notation (see above), which are displayed as two character strings. _p Output characters in the default character set. Nonprinting characters are displayed as a single ``.''. _u Output US ASCII characters, with the exception that control characters are displayed using the following, lower-case, names. Characters greater than 0xff, hexadecimal, are displayed as hexadecimal strings. 000 NUL 001 SOH 002 STX 003 ETX 004 EOT 005 ENQ 006 ACK 007 BEL 008 BS 009 HT 00A LF 00B VT 00C FF 00D CR 00E SO 00F SI 010 DLE 011 DC1 012 DC2 013 DC3 014 DC4 015 NAK 016 SYN 017 ETB 018 CAN 019 EM 01A SUB 01B ESC 01C FS 01D GS 01E RS 01F US 07F DEL The default and supported byte counts for the conversion characters are as follows: %_c, %_p, %_u, %c One byte counts only. %d, %i, %o, %u, %X, %x Four byte default, one, two and four byte counts supported. %E, %e, %f, %G, %g Eight byte default, four and twelve byte counts supported. The amount of data interpreted by each format string is the sum of the data required by each format unit, which is the iteration count times the byte count, or the iteration count times the number of bytes required by the format if the byte count is not specified. The input is manipulated in ``blocks'', where a block is defined as the largest amount of data specified by any format string. Format strings interpreting less than an input block's worth of data, whose last format unit both interprets some number of bytes and does not have a specified iteration count, have the iteration count incremented until the entire input block has been processed or there is not enough data remaining in the block to satisfy the format string. If, either as a result of user specification or hexdump modifying the iteration count as described above, an iteration count is greater than one, no trailing whitespace characters are output during the last iteration. It is an error to specify a byte count as well as multiple conversion characters or strings unless all but one of the conversion characters or strings is _a or _A. If, as a result of the specification of the -n option or end-of-file being reached, input data only partially satisfies a format string, the input block is zero-padded sufficiently to display all available data (i.e., any format units overlapping the end of data will display some number of the zero bytes). Further output by such format strings is replaced by an equivalent number of spaces. An equivalent number of spaces is defined as the number of spaces output by an s conversion character with the same field width and precision as the original conversion character or conversion string but with any ``+'', `` '', ``#'' conversion flag characters removed, and referencing a NULL string. If no format strings are specified, the default display is equivalent to specifying the -x option. EXIT STATUS
The hexdump and hd utilities exit 0 on success, and >0 if an error occurs. EXAMPLES
Display the input in perusal format: "%06.6_ao " 12/1 "%3_u " " " "%_p " " " Implement the -x option: "%07.7_Ax " "%07.7_ax " 8/2 "%04x " " " Some examples for the -e option: # hex bytes % echo hello | hexdump -v -e '/1 "%02X "' ; echo 68 65 6C 6C 6F 0A # same, with ASCII section % echo hello | hexdump -e '8/1 "%02X "" "" "' -e '8/1 "%c"" "' 68 65 6C 6C 6F 0A hello # hex with preceding 'x' % echo hello | hexdump -v -e '"x" 1/1 "%02X" " "' ; echo x68 x65 x6C x6C x6F x0A # one hex byte per line % echo hello | hexdump -v -e '/1 "%02X "' 68 65 6C 6C 6F 0A # a table of byte#, hex, decimal, octal, ASCII % echo hello | hexdump -v -e '/1 "%_ad# "' -e '/1 "%02X hex"' -e '/1 " = %03i dec"' -e '/1 " = %03o oct"' -e '/1 " = _%c\_ "' 0# 68 hex = 104 dec = 150 oct = _h_ 1# 65 hex = 101 dec = 145 oct = _e_ 2# 6C hex = 108 dec = 154 oct = _l_ 3# 6C hex = 108 dec = 154 oct = _l_ 4# 6F hex = 111 dec = 157 oct = _o_ 5# 0A hex = 010 dec = 012 oct = _ _ # byte# & ASCII with control chars % echo hello | hexdump -v -e '/1 "%_ad# "' -e '/1 " _%_u\_ "' 0# _h_ 1# _e_ 2# _l_ 3# _l_ 4# _o_ 5# _lf_ SEE ALSO
gdb(1), od(1) BSD
October 29, 2014 BSD
All times are GMT -4. The time now is 04:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy