The UNIX and Linux Forums  


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
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 9 12-04-2008 04:04 PM
Combining Two fixed width columns to a variable length file manneni prakash Shell Programming and Scripting 4 06-24-2008 09:46 AM
Help with Fixed width File Parsing sate911 UNIX Desktop for Dummies Questions & Answers 4 05-19-2008 12:18 PM
Fixed Width file using AWK alok.benjwal UNIX for Dummies Questions & Answers 2 12-05-2005 11:39 AM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 01:09 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Comparing column of variable length anf fixed width file

Hi, I have two input files.

File1:

ID Name Place
1-234~name1~Newyork
1-34~name2~Boston
1-2345~name3~Hungary

File1 is a variable length file where each column is seperated by delimitter "~".

File2:

ID Country
1-34<<11 SPACES>>USA<<7 spaces>>
1-234<<10 SPACES>>UK<<8 spaces>>

File2 is a fixed length file where Id is of 15 characters length and Country is of 10 characters length.

I need an output file such that based on ID file1 and file2 should be compared and Place column in file1 should be replaced by country column.

Output File:

ID Name Country
1-234~name1~UK
1-34~name2~USA

Thanks in advance.
  #2 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,330

Code:
awk 'NR==FNR{a[$1]=$2;next}a[$1]{print $1, $2, a[$1]}' File2 File1

Regards
  #3 (permalink)  
Old 06-24-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Quote:
Originally Posted by Franklin52 View Post
Code:
awk 'NR==FNR{a[$1]=$2;next}a[$1]{print $1, $2, a[$1]}' File2 File1

Regards
Thanks for the reply. I have tried this but when Iam trying to use awk its not working .... but nawk works instead. Is there any alternative thing where I can write a shell scripting to replace Place column of variable length file with Country column of fixed length file. Thanks in advance.
  #4 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,330
To print the 3th field in a fixed column of 20 characters you can use printf instead of print:


Code:
printf("%s % s%20s\n", $1, $2, a[$1)

Regards
  #5 (permalink)  
Old 06-24-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Thanks franklin for that reply. But I heard that we can do a validation on the delimiter "~" and can divide the record using SUBSTR command and can replace the column by another column of another file . Is it possible ? Thanks in advance.
  #6 (permalink)  
Old 06-25-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Need Help

I have tried using awk and nawk but I could not able to get it. Please let me know how to get out of this issue...
Closed Thread

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 06:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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