LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-17-2007, 07:15 PM   #1
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Rep: Reputation: 32
how to append columns form a column file in another file


hello all


i want to know how to write abash script that append columns form a column file in another file

ia have tried many things but it failed


cut -f 1 -d " " test1 >> hello.txt & cut -f 2 -d " " >> hello.txt


awk '{print $1}' test1 > hello.txt | cut -f 2 -d " " >> hello.txt


awk '{print $1}' test1 > hello.txt && cut -f 2 -d " " >> hello.txt


can any one give me a help and any help will be appreciated
 
Old 09-17-2007, 07:45 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Maybe something like this...
Code:
cut -d" " -f1,2 file.txt > file1.txt
or
awk '{print$1" "$2}' file.txt > file1.txt
 
Old 09-17-2007, 08:10 PM   #3
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
tahnks for you help but what i mean i want to append 2 columns from 2 different files to another file :

the contents of the first file :
adams smith
sara wittel

the contents of the second file :

age 22
age 33


after appending will make new file has the contents

adams 22
sara 33
 
Old 09-17-2007, 10:26 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
sorry, misunderstood that part.
Maybe paste will do...
Code:
 paste -d" " file1.txt file2.txt | cut -d" " -f1,4 > file3.txt
 
Old 09-17-2007, 11:33 PM   #5
adam_blackice
Member
 
Registered: Apr 2006
Location: /*Egypt */ //cairo
Distribution: Ubuntu 7.04 , SLED 10 , Fedora , RHEL 5
Posts: 312

Original Poster
Rep: Reputation: 32
thanks very much
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[Perl] append columns to file noir911 Programming 3 02-08-2007 05:29 AM
delete columns 15 to 27 of a text file powah Programming 1 01-31-2007 02:03 AM
how to exchange two columns of a file jackk294 Programming 8 07-11-2006 11:37 PM
Reading in data in columns from a file (C++) Nylex Programming 4 03-08-2006 05:55 PM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration