Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk GSUB read field values from multiple text files Post 302974893 by dellanicholson on Sunday 5th of June 2016 05:15:53 PM
Old 06-05-2016
awk GSUB read field values from multiple text files

My program run without error. The problem I am having.

The program isn't outputting field values with the column headers to file.txt.

Each of the column headers in file.txt has no data.

Code:
MEMSIZE  SECOND SASFoundation  Filename


The output results in file.txt should show:

Code:
MEMSIZE   SECOND      SASFoundation            Filename
200                                                             LT_5h_MEMSIZE.txt
400          06:00:00       SASFoundation            GT_5hr.txt

I realized the problem is gsub. I don't know enough about gsub to fix this
issue.

Code:
$1 in L{v=$2;gsub("^[/]*","",v)gsub(/*$/,"",v);gsub(v=$2"^[/]*","",v);K[L[$1]]=v}

The first gsub stored the field value for MEMSIZE and second gsub
stored the field value for real time and the last gsub stored the field
value for SASFoundation. The field values for headers are outputted to file.txt

Code:
#!/bin/bash

cd /tmp/log/*.log
awk -F '[= '':;.]' '
function pr() {if(NR>1) printf "%s\t%s\t%s\t%s\n", K[1],K[2],K[3],K[0]}
BEGIN {
printf "MEMSIZE\tSECOND\tSASFoundation\tFilename\n"
for(i=split("MEMSIZE ,real time ,SASFoundation",A,",");i;i--) L[A[i]]=i
}
FNR==1 {
pr()
K[0]=FILENAME
K[1]=K[2]=K[3]=x
}
$1 in L {v=$2;gsub("^[/ ]*","",v)gsub(/ *$/,"",v);gsub(v=$2"^[/ ]*","",v);K[L[$1]]=v}
 END{if(K[1] || K[2]>'5:00:00' || K[3]) pr()} *.txt > file.txt
[ -s file.txt ] && mailx -s "subject text" -a  file.txt receiver@domain.com < "Code Need to be Evaluated"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to apply sub/gsub of awk on a particular field?

I got a file with contents are of the following format ... 2007-09-28 ./.passwwd1.sh.swp 2007-11-26 ./827-55.jpg 2007-09-28 ./argcheck.pl ... I have to delete all the '-' in the "first field", ie. the date, not on the second field, which is the name of the file. i.e. required output ... (1 Reply)
Discussion started by: jaduks
1 Replies

2. Shell Programming and Scripting

Computing average values from multiple text files

Hi, first, I have searched in the forum for this, but I could not find the right answer. (There were some similar threads, but I was not sure how to adapt the ideas.) Anyway, I have a quite natural problem: Given are several text files. All files contain the same number of lines and the same... (3 Replies)
Discussion started by: rbredereck
3 Replies

3. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

4. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 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. UNIX for Dummies Questions & Answers

Changing the values of a column using awk and gsub

Hi, I am using the following code to change NA to X in only the 5th column of my text file: awk '{gsub("NA","x",$5)}1' in.file > out.file How can I modify this code if I want to change NA to X in multiple columns of the text file (i.e. columns 5,6 and 7). Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

7. Shell Programming and Scripting

Read text between regexps and write into files based on a field in the text

Hi, I have a huge file that has data something like shown below: huge_file.txt start regexp Name=Name1 Title=Analyst Address=Address1 Department=Finance end regexp some text some text start regexp Name=Name2 Title=Controller Address=Address2 Department=Finance end regexp (7 Replies)
Discussion started by: r3d3
7 Replies

8. Shell Programming and Scripting

awk read in file1, gsub in file2, print to file3

I'm trying to use awk to do the following. I have file1 with many lines, each containing 5 fields describing an individual set. I have file2 which is a template config file with variable space holders to be replaced by the values in file1. I would like to substitute each set of values in file1 with... (6 Replies)
Discussion started by: msmehaffey
6 Replies

9. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

10. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies
X2SYS_REPORT(1gmt)					       Generic Mapping Tools						X2SYS_REPORT(1gmt)

NAME
x2sys_report - Report statistics from crossover data base SYNOPSIS
x2sys_report -Ccolumn -TTAG [ coedbase.txt ] [ -A ] [ -I[list] ] [ -L[corrtable] ] [ -Nnx_min ] [ -Qe|i ] [ -Rwest/east/south/north[r] ] [ -Strack ] [ -V ] DESCRIPTION
x2sys_report will read the input crossover ASCII data base coedbase.txt (or stdin) and report on the statistics of crossovers (n, mean, stdev, rms, weight) for each track. Options are available to let you exclude tracks and limit the output. -C Specify which data column you want to process. Crossovers related to this column name must be present in the crossover data base. -T Specify the x2sys TAG which tracks the attributes of this data type. OPTIONS
No space between the option flag and the associated arguments. coedbase.txt The name of the input ASCII crossover error data base as produced by x2sys_cross. If not given we read standard input instead. -A Eliminate COEs by distributing the COE between the two tracks in proportion to track weight and producing (dist, adjustment) spline knots files for each track (for the selected column). Such adjustments may be used by x2sys_datalist. The adjustment files are called track.column.adj and are placed in the $X2SYS_HOME/TAG directory. For background information on how these adjustments are designed, see Mittal [1984]. -I Name of ASCII file with a list of track names (one per record) that should be excluded from consideration [Default includes all tracks]. -L Apply optimal corrections to the chosen observable. Append the correction table to use [Default uses the correction table TAG_cor- rections.txt which is expected to reside in the $X2SYS_HOME/TAG directory]. For the format of this file, see x2sys_solve. -N Only report data from tracks involved in at least nx_min crossovers [all tracks]. -Q Append e for external crossovers or i for internal crossovers only [Default is external]. -R west, east, south, and north specify the Region of interest, and you may specify them in decimal degrees or in [+-]dd:mm[:ss.xxx][W|E|S|N] format. Append r if lower left and upper right map coordinates are given instead of w/e/s/n. The two shorthands -Rg and -Rd stand for global domain (0/360 and -180/+180 in longitude respectively, with -90/+90 in latitude). Alterna- tively, specify the name of an existing grid file and the -R settings (and grid spacing, if applicable) are copied from the grid. For Cartesian data just give xmin/xmax/ymin/ymax. This option bases the statistics on those COE that fall inside the specified domain. -S Name of a single track. If given we restrict output to those crossovers involving this track [Default output is crossovers involv- ing any track pair]. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. EXAMPLES
To report statistics of all the external magnetic crossovers associated with the tag MGD77 from the file COE_data.txt, restricted to occupy a certain region in the south Pacific, try x2sys_report COE_data.txt -V -TMGD77 -R180/240/-60/-30 -Cmag > mag_report.txt To report on the faa crossovers globally that involves track 12345678, try x2sys_report COE_data.txt -V -TMGD77 -Cfaa -S12345678 > faa_report.txt REFERENCES
Mittal, P. K.(1984), Algorithm for error adjustment of potential field data along a survey network, Geophysics, 49(4), 467-469. SEE ALSO
x2sys_binlist(1) x2sys_cross(1) x2sys_datalist(1) x2sys_get(1) x2sys_init(1) x2sys_list(1) x2sys_put(1) x2sys_solve(1) GMT 4.5.7 15 Jul 2011 X2SYS_REPORT(1gmt)
All times are GMT -4. The time now is 03:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy