The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
input box ruben.rodrigues Shell Programming and Scripting 2 01-28-2009 06:17 AM
msg input box ruben.rodrigues UNIX for Dummies Questions & Answers 0 01-28-2009 04:34 AM
Reading specific contents from 1 input files and appending it to another input file sksahu Shell Programming and Scripting 5 01-14-2009 06:09 AM
assign vales to arrary koti_rama Shell Programming and Scripting 0 07-24-2007 02:43 AM
How to prompt for input & accept input in ONE line newbie168 Shell Programming and Scripting 2 09-27-2005 05:02 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
garethsays garethsays is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 11
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
Attached Files
File Type: txt foo1.txt (3.7 KB, 11 views)

Last edited by Franklin52; 05-26-2009 at 07:30 AM.. Reason: Unreadable, adding code tags
  #2 (permalink)  
Old 05-26-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
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 (permalink)  
Old 05-26-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,047
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 (permalink)  
Old 05-26-2009
garethsays garethsays is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 11
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 (permalink)  
Old 05-26-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
What is the format of foo2 without using the fold command?
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0