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
insert new line at found chars crowman Shell Programming and Scripting 6 09-25-2008 04:03 PM
how can i compare te length of the string mail2sant Shell Programming and Scripting 6 09-16-2008 04:00 AM
compare the column from 3 files and merge that line ganesh_mak Shell Programming and Scripting 8 04-14-2008 07:56 AM
Get multiple line content between two chars Feliz Shell Programming and Scripting 2 04-11-2008 12:29 PM
Using PERL to append chars to each line c0nn0r Shell Programming and Scripting 5 07-11-2006 07:55 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 10-19-2008
elj3dah elj3dah is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
How to Compare two files depend on line length Chars

I need to compare two files with exactly same length as example: -

File1 contain 500 records with length of 640 chars of each line.
File2 contain 1500 records with length of 640 chars of each line.

I need get an output to be written in File3 which will contain 1000 records difference.
but my diff will be based on line length which is 630 chars and ignore the remaining 10 chars in comparing.
However, file3 I wanted to include all 1000 records with 640 chars lenght for each line.

Thanks in advance
  #2 (permalink)  
Old 10-19-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 573
Try:

Code:
paste file1 file2  | awk '{ str1=substr($1,0,629); str2=substr($2,0,629); if(str1 != str2) print str1"\n"str2; }' > file3
  #3 (permalink)  
Old 10-19-2008
elj3dah elj3dah is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Many Thanks for your swift reply,

However, this is not what I am looking for, let me example it to be easier for understanding in order to help me.

File1 contain 500 records and each line lenght has 640 chars
File2 contain 1500 records and each line length has 640 chars.

Now;
My File2 will be my source, I need one line length of 630 chars from File2 to check if it's exist in File1, If yes, then go to second line search.
Else, copy this line into new file (File3) but this time with exact line length of 640 from the orginal instead of 630 chars.

I hope this make it clear.

Thanks.
  #4 (permalink)  
Old 10-19-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,421
This should work:
Code:
while read l;do test $(grep -c ${l:0:630} file1) -eq 0 &&  echo "$l" >> file3 ;done < file2
  #5 (permalink)  
Old 10-20-2008
elj3dah elj3dah is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Dear,

Thanks for the help, but still this didn't help me
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 07:45 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