awk help - input vales from on efile to annother


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk help - input vales from on efile to annother
# 1  
Old 05-26-2009
awk help - input vales from on efile to annother

Please see attached test file for better explanation and formatting of files....thanks

foo1

Code:
H2600 LINE: 
H2600
H2600
H2600 MYSystems Ltd. (Feb 18 2009) 
V1760R1130      1    2213133522.79N 81 027.09E 500814.01502345.9      145 9 837
E1760R1130      1 2  2213133522.44N 81 027.33E 500821.11502335.1      145 9 837
Z1760R1130      11   2213133512.77N 81 031.86E 500957.51502038.3      145 9 837
Z1760R1130      12   2213133512.15N 81 030.27E 500909.81502019.1      145 9 837
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2214133523.56N 81 026.81E 500805.51502369.5      145 9 849
E1760R1130      1 2  2214133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2214133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2214133512.93N 81 029.98E 500900.81502042.9      145 9 849
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2392133740.94N 805939.69E 499389.81506589.83182.4145 94330
E1760R1130      1 2  2392133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2392133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2392133512.93N 81 029.98E 500900.81502042.9      145 9 849



foo2

Code:
key    key
2213    3200    
2214    3198
2392    3182



I would like to read through foo1 and replace column 65 to 70 with $2 from foo2 if
line in foo1 starts with V and columns 65 to 70 are blank and if columns 22 to 25 in foo1 match $1 from foo2.

Also the file foo2 does not seem to have any record sepeator and I would like to set NR to be equal to 80 characters.

So my output file will look like

Code:
H2600 LINE: 
H2600
H2600
H2600 MYSystems Ltd. (Feb 18 2009) 
V1760R1130      1    2213133522.79N 81 027.09E 500814.01502345.93200  145 9 837
E1760R1130      1 2  2213133522.44N 81 027.33E 500821.11502335.1      145 9 837
Z1760R1130      11   2213133512.77N 81 031.86E 500957.51502038.3      145 9 837
Z1760R1130      12   2213133512.15N 81 030.27E 500909.81502019.1      145 9 837
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2214133523.56N 81 026.81E 500805.51502369.53198  145 9 849
E1760R1130      1 2  2214133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2214133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2214133512.93N 81 029.98E 500900.81502042.9      145 9 849
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2392133740.94N 805939.69E 499389.81506589.83182.4145 94330
E1760R1130      1 2  2392133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2392133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2392133512.93N 81 029.98E 500900.81502042.9      145 9 849


Last edited by Franklin52; 05-26-2009 at 08:30 AM.. Reason: Unreadable, adding code tags
# 2  
Old 05-26-2009
Try this:

Code:
awk 'NR==FNR{a[$1]=$2;next}
/^V/ && substr($0,65,5)=="     " && substr($0,22,4) in a {
  print substr($0,1,64) a[substr($0,22,4)] substr($0,69);next
}
1' foo2 foo1

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.
# 3  
Old 05-26-2009
Code:
my %hash=(
2213  =>  3200,   
2214  =>  3198,
2392  =>  3182,
);
while(<DATA>){
	if(/^V/ && (substr($_,64,6)=~/\s{6}/)){
		substr($_,64,4)=$hash{substr($_,21,4)};
	}
	print;
}

__DATA__
H2600 LINE: 
H2600
H2600
H2600 MYSystems Ltd. (Feb 18 2009) 
V1760R1130      1    2213133522.79N 81 027.09E 500814.01502345.9      145 9 837
E1760R1130      1 2  2213133522.44N 81 027.33E 500821.11502335.1      145 9 837
Z1760R1130      11   2213133512.77N 81 031.86E 500957.51502038.3      145 9 837
Z1760R1130      12   2213133512.15N 81 030.27E 500909.81502019.1      145 9 837
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2214133523.56N 81 026.81E 500805.51502369.5      145 9 849
E1760R1130      1 2  2214133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2214133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2214133512.93N 81 029.98E 500900.81502042.9      145 9 849
R   1 501299.31502012.1 6.7   2 501303.51502000.2 6.8   3 501307.71501988.4 7.01
R   4 501311.91501976.6 7.1   5 501316.21501964.7 7.3   6 501320.41501952.9 7.41
R   7 501324.61501941.2 7.5   8 501328.91501929.3 7.5   9 501333.21501917.5 7.51
R  10 501337.41501905.7 7.5  11 501341.71501893.9 7.5  12 501346.01501882.1 7.51
V1760R1130      1    2392133740.94N 805939.69E 499389.81506589.83182.4145 94330
E1760R1130      1 2  2392133523.21N 81 027.04E 500812.61502358.7      145 9 849
Z1760R1130      11   2392133513.54N 81 031.57E 500948.61502061.8      145 9 849
Z1760R1130      12   2392133512.93N 81 029.98E 500900.81502042.9      145 9 849

# 4  
Old 05-26-2009
modifications

What I meant to say was that foo2 does not have any Record Seperator.

awk '{print NR}' foo1
returns an answer of 1

The attached file is the printout to screen using the fold command.
# 5  
Old 05-26-2009
What is the format of foo2 without using the fold command?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Parse input -AWK

Input File Defined configuration: cfg: CLL_DCC_Fabric_A BTS00P21; BAU_AP00P01QC; BAU_LGSCNJP02; BAU_TS00P20; BAU_DSMSM14; BAU_HT00P02; BAU_DSMSM13; BAU_HT00P01; cfg: CX0014_list BAU_TS00P20; BAU_NYP_PRODIAD1_CJ;... (5 Replies)
Discussion started by: greycells
5 Replies

3. Shell Programming and Scripting

AWK using two input files

Hi , i have two input files one is input.gz and another is ( input.txt) text file.in gz format input file each record contains 10 fields and corresponding header value is present in the text file as a single record i.e text file contains only 10 records which is header value,so output of the awk... (1 Reply)
Discussion started by: Ajoy
1 Replies

4. Shell Programming and Scripting

How to take input from user or awk script?

Hi Jim, I have following script,i which i need to take dynamic value . script, nawk -v v1=grep"INT_EUR" $propertifilename | cut -d"=" -F2` -F'~' '{if (NF-1 !=v1) {print "Error in " $0 " at line number "NR" tilde count " N-1}}' $filename In the above script i want to use INT_EUR as a variable... (2 Replies)
Discussion started by: Ganesh Khandare
2 Replies

5. Shell Programming and Scripting

Comparing 2 input files -Awk

Compare 2 files and print the values input1 (c1 20 100 X_y10) along with one closest highest (c1 100 200 X_y10) and one lowest values (c1 10 15 X_y10) from input2 input1 c1 20 100 X_y10 input2 c1 5 10 X_y10 c1 10 15 X_y10 c1 100 200 X_y10 c1 200 300 X_y10 output ... (8 Replies)
Discussion started by: bumblebee_2010
8 Replies

6. Shell Programming and Scripting

awk user input

Using the following I'm trying to print the user's response to the prompt Y / N but I get nothing other than the contents of $1? awk '{ printf($1 " ? (Y/N)") getline myresponse < "-" system("read myresponse") if (myresponse == "Y") { print $1... (17 Replies)
Discussion started by: gefa
17 Replies

7. Shell Programming and Scripting

2 input files for awk

Hi, i have 2 files like f1 and f2 f1: 1 Note: some times it will be cahnged to 2 and 3. f2: 1:20 2:30 4:50 6:70 8:90 3:20 1:30 1:40 output: 1:80 (sum of 1) (6 Replies)
Discussion started by: koti_rama
6 Replies

8. Shell Programming and Scripting

awk/input parameter

Hi, My script takes in one input parameter($1-email id) on the command line... The script contains something like this... awk '$1 == 400' abc.log >def.log mail -s subject $1 <def.log abc.log looks something like this... 300 222 330 123 445 400 098 890 727 663 How do i make the... (3 Replies)
Discussion started by: wannalearn
3 Replies

9. Shell Programming and Scripting

assign vales to arrary

Hi all how can assign values from grep command to array?. my grep command returning more than two values. regards koti. (0 Replies)
Discussion started by: koti_rama
0 Replies

10. Shell Programming and Scripting

awk - input function

hello, im a newbie. how can i input data from keyboard? thanks. (3 Replies)
Discussion started by: Jariya
3 Replies
Login or Register to Ask a Question