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
Merge 3 columns side by side amaulana Shell Programming and Scripting 7 02-08-2009 02:50 AM
Merge 2 text files to one text file side by side ahinkebein Shell Programming and Scripting 15 02-04-2009 11:28 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 2 09-24-2008 07:44 AM
How to Merge Two .xls files side by side into a single .xls jagadish99 Shell Programming and Scripting 0 08-27-2008 07:38 AM
How to print two sql query outputs side by side in excel prasee Shell Programming and Scripting 6 09-08-2007 03:20 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 02-11-2009
ks_reddy ks_reddy is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 24
Script to place selected columns from a group of files side by side in a new file

Hi Everyone,

I need a shell/perl script to bring selected columns from all the files located in a directory and place them in a new file side by side.

File1:
a b c d
2 3 4 5
f g h i
..........
File2:

I II III IV
w x y z
..............
and so on many files are there...

My Output for selected columns(example 1 and 2) from source files should be:

a b I II..........................so on(here last file contents)
2 3 W X..........................so on(here last file contents)
f g
............ So on

Thanks in advance ........
  #2 (permalink)  
Old 02-11-2009
quirkasaurus's Avatar
quirkasaurus quirkasaurus is offline
Registered User
  
 

Join Date: Jan 2009
Location: canton, michigan
Posts: 373
you can grab the columns using:

awk '{ print $1, $2 }' file_nm > file_nm_out

and combine ( up to 12 -- but some characters might get swallowed up )
the 2-column-output-files with paste:

paste file1 file2 > file_comb.1

However, with lots of files... this will become a little bit of a challenge.

I'm willing to bet there's an easier approach to your actual problem.

meaning -- why do the first 2 columns need to appear in a new file?
and how many files are we actually talking about?
what is the final destination for this data file we're building?
how were the initial files created in the first place?

it seems if we redesign any one of these steps, we might be able to design a better end-to-end process.

Perhaps you could restate the actual issue?
  #3 (permalink)  
Old 02-11-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,431
Code:
awk 'NR==FNR{_[NR]=$0;next}{print $1,$2,_[FNR]}' file2 file1
  #4 (permalink)  
Old 02-12-2009
ks_reddy ks_reddy is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 24
Pasting the columns in new file as it is... Urgent...

I want to place the selected column(s) from all the files (e.g. col 2 from all files together) from a directory, not just two files....

I tried this command: paste | awk '{print $2}' *
But I got the output one after the other in a new file.

$2 from 1st file
$2 from 2nd file
.............. so on..

But what I need is $2 from 1st file <tab> $2 from 2nd file<tab> ..............so on....

I have thousands of files with me All are similar files. They contains 34 columns and 1000 rows. Please help me...

Finally I need to plot one column from one file against the other columns from other files depending on the column header.
  #5 (permalink)  
Old 02-12-2009
ce9888 ce9888 is offline
Registered User
  
 

Join Date: Aug 2008
Location: Montreal, Qc, CA
Posts: 98
awk '{printf "\t",$2}' *
  #6 (permalink)  
Old 02-12-2009
ks_reddy ks_reddy is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 24
This command awk '{printf "\t", $2 }' did not work for me. I tried already. Can anybody explain the reason??
  #7 (permalink)  
Old 02-12-2009
rakeshou rakeshou is offline
Registered User
  
 

Join Date: May 2007
Posts: 75
have you tried paste command?
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 02:01 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