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
Help with Fixed width File Parsing sate911 UNIX Desktop for Dummies Questions & Answers 4 05-19-2008 12:18 PM
Changing particular field in fixed width file dsravan Shell Programming and Scripting 4 02-11-2008 06:08 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
Combining Two fixed width columns to a variable length file

Hi, I have two files.

File1:

File1 contains two fixed width columns ID of 15 characters length and Name is of 100 characters length.

ID Name
1-43<<11 spaces>>Swapna<<94 spaces>>
1-234<<10 spaces>>Mani<<96 spaces>>
1-3456<<9 spaces>>Kapil<<95 spaces>>

File2:

File2 contains two fixed width columns ID of 15 characters length and Name is of 80 characters length.

ID Place
1-3456<<10 spaces>>Boston<<74 spaces>>
1-43<<11 spaces>>London<<74spaces>>

I need an output file of variable length file as follows

Output:

The Output file should contain the matched records of both File1 and File2 based on ID column.

Id Name
1-43<<1 space>>Swapna
1-234
1-3456<<1 space>>Kapil

Thanks in Advance.
  #2 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,313
Try this:

Code:
awk 'NR==FNR{a[$1]=$2;next}{print $1, a[$1]}' File1 File2
Regards
  #3 (permalink)  
Old 06-24-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Thanks for the reply......I have tried by giving the command...............

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

or

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

But Iam getting the output as

Id Name
1-43<<1 space>>Swapna
1-3456<<1 space>>Kapil

But I need output as

Id Name
1-43<<1 space>>Swapna
1-234
1-3456<<1 space>>Kapil
  #4 (permalink)  
Old 06-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,313
Code:
awk '
NR==FNR{a[$1]=$2;next}
a[$1]{print $1, $2;next}
{print $1}' File2 File1
Regards
  #5 (permalink)  
Old 06-24-2008
manneni prakash manneni prakash is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 30
Thanks

Thanks Franklin...... I got the desired output By giving the following connamd..........

nawk 'NR==FNR{a[$1]=$2;next} a[$1]{print $1, $2;next}{print $1}' file2 file1 > file3

Thanks Once again..............
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:28 AM.


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