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
Conditionally joining lines in vi ifermon UNIX for Dummies Questions & Answers 0 06-04-2008 10:43 AM
Joining 3 lines at a time Sabari Nath S Shell Programming and Scripting 14 12-21-2005 01:29 AM
Joining 2 lines in a file together m223464 Shell Programming and Scripting 3 05-12-2005 12:42 PM
Joining multiple lines beilstwh Shell Programming and Scripting 4 03-02-2005 05:51 AM
Joining lines in log file bubba112557 Shell Programming and Scripting 3 05-18-2004 08:10 AM

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 07-21-2006
chandra004 chandra004 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
Joining lines from two files - please help

Hello,
I have 2 files say
File 1 has
ABC
DEF
GHI
File 2 has
123
456
789

I need output as
ABC 123
DEF 456
GHI 789

I tried awk and sed but not able to get it in the right way.
Please help. Thanks
  #2 (permalink)  
Old 07-21-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
paste file1 file2 > joined_file
  #3 (permalink)  
Old 07-21-2006
chandra004 chandra004 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
That helps, Thanks. I am looking for some thing like, even if 123 is in a different line on file2, it has to print next to ABC.
What I am trying to do is, I am doing ls -lrt on two directories which have same files ,and printing filename and the size to a file.
Now I want those two files with filename and filesize to be in the output file so that I can compare the file sizes.
When I say paste, it works when there are exactly same files in the directories, but if there is an extra file in any one dir, the pattern changes.

Any ideas ???
  #4 (permalink)  
Old 07-21-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
You could try something like this:

Code:
    printf "%-40s %-15s %-15s %-15s\n" "File" "Size Location 1" "Size Location 2" "Difference"
    print "========================================" "===============" "===============" "==============="
    for i in $(ls -1F /your/first/path)
    do
        [[ ${i} = */ ]] && continue
        FILE_SIZE_1=$(ls -l /your/first/path/${i} | nawk '{print $5}')
        FILE_SIZE_2=$(ls -l /your/second/path/${i} | nawk '{print $5}')
        printf "%-40s %15d %15d %15d\n" "${i}" "$FILE_SIZE_1" "$FILE_SIZE_2" "$(( FILE_SIZE_1 - FILE_SIZE_2 ))"
    done

  #5 (permalink)  
Old 07-24-2006
chandra004 chandra004 is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 19
Thank you very much, 'tmarikle'. It really helped and I am trying to extend your script for recursively checking in any/all of the directories also under the path. Not able to make the loop work. Can you advise?

Thanks
chandra
  #6 (permalink)  
Old 07-24-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
What does your loop look like now? What habe you tried?
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 08:19 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