Sponsored Content
Top Forums UNIX for Dummies Questions & Answers append column and row header to a file in awk script. Post 302683099 by zaxxon on Tuesday 7th of August 2012 07:50:10 AM
Old 08-07-2012
Code:
$ awk 'BEGIN{printf("%-3s%-8s%-6s%-5s%-20s\n","#","name","gend","age","occup")}{printf("%-3s%-8s%-6s%-5s%-20s\n",NR,$1,$2,$3,$4)}' infile
#  name    gend  age  occup
1  Jane    F     39   manager
2  Carlos  M     40   system
3  Sam     F     20   programmer

This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

split header row into one column

So, I have a massive file with thousands of columns I want a list of the headers in one column in another file. So I need to strip off the top line (can use head-1) But how can I convert from this format: A B C D E F G to A B C D E F G (6 Replies)
Discussion started by: polly_falconer
6 Replies

2. Shell Programming and Scripting

AWK Script - Print a column - within a Row Range

Hi, Please read the whole thread. I have been working on this script below. It works fine, feel free to copy and test with the INPUT File below as well. example: PACKET DATA PROTOCOL CONTEXT DATA APNID PDPADD EQOSID VPAA PDPCH PDPTY PDPID 10 ... (6 Replies)
Discussion started by: panapty
6 Replies

3. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

4. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

5. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Awk/sed script for transposing any number of rows with header row

Greetings! I have been trying to find out a way to take a CSV file with a large number of rows, and a very large number of columns (in the thousands) and convert the rows to a single column of data, where the first row is a header representing the attribute name and the subsequent series of... (3 Replies)
Discussion started by: tntelle
3 Replies

7. Shell Programming and Scripting

Matching column value from 2 different file using awk and append value from different column

Hi, I have 2 csv files. a.csv HUAWEI,20LMG011_DEKET_1296_RTN-980_IDU-1-11-ISV3-1(to LAMONGAN_M),East_Java,20LMG011_DEKET_1296_RTN-980_IDU-1,20LMG011,20LMG 027_1287_LAMONGAN_RTN980_IDU1,20LMG027,1+1(HSB),195.675,20LMG011-20LMG027,99.9995,202.6952012... (7 Replies)
Discussion started by: tententen
7 Replies

8. Shell Programming and Scripting

awk script row to column

Hi.. I have data : Report testing1 20180419 08:00 Report testing2 20180419 07:35 Report testing 20180419 08:01 Source = data1 Report testing4 20180419 08:05 Source = data1 Report testing5 20180419 08:10 Source = data2 Report testing6 20180419 08:01 Report testing7 20180419 08:19... (4 Replies)
Discussion started by: buncit8
4 Replies

9. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

10. UNIX for Beginners Questions & Answers

Script to do column to row in awk

Hi , Can anyone help me suggesting - how to do the below trick with awk Input 120 130 140 210 310 410 645 729 800 Output 120 130 140 (6 Replies)
Discussion started by: Indra2011
6 Replies
GRD2XYZ(l)																GRD2XYZ(l)

NAME
grd2xyz - Converting a grdfile to an ASCII or binary table SYNOPSIS
grd2xyz grdfile [ -H[nrec] ] [ -L ] [ -Rwest/east/south/north[r] [ -S[r ] [ -V ] [ -Z[flags] ] [ -bo[s][n] ] DESCRIPTION
grd2xyz reads a binary 2-D grdfile and writes out xyz-triplets in ASCII [or binary] format to standard output. Modify the precision of the ASCII output format by editing the D_FORMAT parameter in your .gmtdefaults file, or choose binary output using single or double precision storage. As an option you may output z-values without the (x,y) in a number of formats, see -Z below. grdfile The 2-D binary file to be converted. OPTIONS
-H Output 1 header record based on information in the grdfile header. Ignored if binary output is selected. [Default is no header]. -L Indicates that the x values are longitudes (necessary for -: to work). -R west, east, south, and north specify the Region of interest. To specify boundaries in degrees and minutes [and seconds], use the dd:mm[:ss] format. Append r if lower left and upper right map coordinates are given instead of wesn. -S Suppress output for nodes whose z-value equals NaN [Default outputs all nodes]. Append r to reverse the suppression, i.e., only output the nodes whose z-value equals NaN. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. -Z Write a 1-column ASCII [or binary] table. Output will be organized according to the specified ordering convention contained in flags. If data should be written by rows, make flags start with T(op) if first row is y = ymax or B(ottom) if first row is y = ymin. Then, append L or R to indicate that first element should start at left or right end of row. Likewise for column formats: start with L or R to position first column, and then append T or B to position first element in a row. For gridline registered grids: If grid is periodic in x but the outcoming data should not contain the (redundant) column at x = xmax, append x. For grid periodic in y, skip writing the redundant row at y = ymax by appending y. If the byte-order needs to be swapped, append w. Select one of several data types (all binary except a): a ASCII representation c signed 1-byte character u unsigned 1-byte character h short 2-byte integer i 4-byte integer l long (4- or 8-byte) integer f 4-byte floating point single precision d 8-byte floating point double precision Default format is scanline orientation of ASCII numbers: -ZTLa. Note that -Z only applies to 1-column output. -bo Selects binary output. Append s for single precision [Default is double]. This option only applies to xyz output; see -Z for z ta- ble output. EXAMPLES
To edit individual values in the 5' by 5' hawaii_grv.grd file, try grd2xyz hawaii_grv.grd > hawaii_grv.xyz To write a single precision binary file without the x,y positions from the file raw_data.grd file, using scanline orientation, try grd2xyz raw_data.grd -ZTLf > hawaii_grv.b SEE ALSO
gmtdefaults(1gmt), gmt(1gmt), grdedit(1gmt), xyz2grd(1gmt) 1 Jan 2004 GRD2XYZ(l)
All times are GMT -4. The time now is 11:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy