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
How to merge different coulmn of differnt files rahul sharma11 Shell Programming and Scripting 10 05-09-2008 04:55 AM
processing matrix column wise Abhishek Ghose Shell Programming and Scripting 5 08-21-2007 01:55 PM
Unix addition ( Row wise) gauravgoel Shell Programming and Scripting 3 05-17-2007 05:27 AM
Manipulating fields record wise rinku11 Shell Programming and Scripting 1 12-07-2005 10:42 AM
System RAM identification slot-wise diliphere UNIX for Advanced & Expert Users 0 08-23-2005 09:45 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 06-26-2006
er_aparna er_aparna is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 52
Paste coulmn wise

Hello,

I need few clarification in types of paste command ussage in coulmn mode :

In a directory i have few file distinguished as *.cpu *.vmem and *.mem

and have coulmn entries like
first cpu file
89576
89576
89576
89576
89576
89576
89576

second cpu file
46312
46312
46312
46312
46312
46312
46312
46312
46312
and third cpu file
46392
46392
46392
46392
46392
46392


and i want my output as
first file,second file, third file
89576,46312,46392
89576,46312,46392
89576,46312,46392
89576,46312,46392
89576,46312,46392
89576,46312,46392


i can do it easily by paste command paste -d"," first cpu file second cpu file third cpu file > output

but i dont know how many number of files there are for cpu extn....

i wrote a script :

ls -ltr |tr -s " " ";" |cut -d";" -f9 |egrep "(.cpu$|.vmem$|.mem$)" > temp1
cut -d"." -f1,2 temp1 |sort -u |> temp2

for var in `cat temp2`
do
paste -d"," $var" >> out
done

But it will paste the file i same coulmn:

Pls suggest possible one line command for it .I think using nawk or sed i can do it but i amd not having good Knowledge of them ...

thanks in advance
Aparna
  #2 (permalink)  
Old 06-26-2006
er_aparna er_aparna is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 52
Hi

I was able to do what i wanted by the following script
ls -ltr *.vmem |tr -s " " ";" |cut -d";" -f9 |sort -n > list_vmem
var1=`tr -s '\n' ' ' < list_vmem`
var2=`tr -s '\n' ',' < list_vmem`
echo $var2 > output_vmem.csv
paste -d"," $var1 >> output_vmem.csv
ls -ltr *.mem |tr -s " " ";" |cut -d";" -f9 |sort -n > list_mem
var1=`tr -s '\n' ' ' < list_mem`
var2=`tr -s '\n' ',' < list_mem`
echo $var2 > output_mem.csv
paste -d"," $var1 >> output_mem.csv
ls -ltr *.cpu |tr -s " " ";" |cut -d";" -f9 |sort -n > list_cpu
var1=`tr -s '\n' ' ' < list_cpu`
var2=`tr -s '\n' ',' < list_cpu`
echo $var2 > output_cpu.csv
paste -d"," $var1 >> output_cpu.csv



But can soembody PLs suggest one line solution for multiple files to be paste coulmn wise when we dont know the number of files to be pasted......

Thanks
  #3 (permalink)  
Old 06-26-2006
bobbyjohnz bobbyjohnz is offline
Registered User
  
 

Join Date: May 2005
Posts: 19
Hi Aparna

You have multiple types of files and unknown count of each . I don't have a single liner as you asked for. But a slighter smaller version than you have in hand. Please try this to see if its of any use

#/bin/ksh
for i in "cpu" "vmem" "mem"
do
paste -d"," *.${i} > ${i}.out
done

As you guess, it makes three files cpu.out, vmem.out and mem.out!!!
  #4 (permalink)  
Old 06-26-2006
er_aparna er_aparna is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 52
Thanks a lot it works.............
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 01:20 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