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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 05:57 AM
Drop a Column from a File Raamc UNIX for Dummies Questions & Answers 4 01-09-2008 06:36 AM
FILE:Adding new column sandeep_hi Shell Programming and Scripting 2 06-09-2006 06:46 AM
cut the third column from a file isingh786 Shell Programming and Scripting 8 12-29-2005 07:11 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-05-2005 10:10 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-22-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
To cut entire column from a file and apend it to another file as another column

file1.txt :
india pakistan bangladesh
japan canada africa
USA srilanka Nepal

file2.txt
Delhi
Tokyo
washington

I have to cut the first column of file1.txt and apend it with file2.txt as another column like this

Delhi india
Tokyo japan
washington USA

Anyone one please say me the syntax for the above .

Last edited by sakthifire; 04-22-2008 at 05:46 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-22-2008
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,198
A possible way :
Code:
awk '{print $1}' file1.txt | paste -d' ' file2.txt -
awk can replaced by cut :
Code:
cut -d' ' -f1 file1.txt  | paste -d' ' file2.txt -
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 04-22-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,454
in a single command
Code:
awk 'BEGIN{ while ( getline < "secondfile" ) { arr[i++]=$0 } }{ print arr[j++], $1 }' firstfile
Reply With Quote
  #4 (permalink)  
Old 04-23-2008
Registered User
 

Join Date: Apr 2008
Posts: 18
Thank you ...

Its working fine...
Reply With Quote
  #5 (permalink)  
Old 06-25-2008
Registered User
 

Join Date: Jun 2008
Posts: 6
It's Simple Buddy

Quote:
Originally Posted by sakthifire View Post
file1.txt :
india pakistan bangladesh
japan canada africa
USA srilanka Nepal

file2.txt
Delhi
Tokyo
washington

I have to cut the first column of file1.txt and apend it with file2.txt as another column like this

Delhi india
Tokyo japan
washington USA

Anyone one please say me the syntax for the above .
Just Use Simple Cmd :
First Cut fhe first field of first file
$ cut -d' ' -f1 <first filename> > tmpfirst
$ cut -d' ' -f2 <second filename> > tmpsecond
$ paste tmpfirst tmpsecond > newfile
(-f1 means first field , -f2 means second field)
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0