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
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 09:57 AM
Drop a Column from a File Raamc UNIX for Dummies Questions & Answers 4 01-09-2008 10:36 AM
FILE:Adding new column sandeep_hi Shell Programming and Scripting 2 06-09-2006 09:46 AM
cut the third column from a file isingh786 Shell Programming and Scripting 8 12-29-2005 11:11 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 01:10 AM

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

Join Date: Apr 2008
Posts: 26
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 08:46 AM..
  #2 (permalink)  
Old 04-22-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
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.
  #3 (permalink)  
Old 04-22-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
in a single command
Code:
awk 'BEGIN{ while ( getline < "secondfile" ) { arr[i++]=$0 } }{ print arr[j++], $1 }' firstfile
  #4 (permalink)  
Old 04-23-2008
sakthifire sakthifire is offline
Registered User
  
 

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

Its working fine...
  #5 (permalink)  
Old 06-25-2008
ch.siva ch.siva is offline
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)
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 11:56 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