Paste coulmn wise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paste coulmn wise
# 1  
Old 06-26-2006
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  
Old 06-26-2006
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  
Old 06-26-2006
Hi Aparna

You have multiple types of files and unknown count of each Smilie . 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 Smilie

#/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  
Old 06-26-2006
Thanks a lot it works.............
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date wise calculations?

POST_DATE CHECK_NUMBER TYPE LOGIN_NAME 2015.09.09 XXXXXXXXXX mark XXXXXXXXXX 2015.09.09 XXXXXXXXXX fsadf XXXXXXXXXX 2015.10.05 XXXXXXXXXX defaa XXXXXXXXXX 2015.10.05 XXXXXXXXXX dewe XXXXXXXXXX 2015.10.06 XXXXXXXXXX dqwe XXXXXXXXXX 2015.09.14 XXXXXXXXXX dt4e XXXXXXXXXX... (22 Replies)
Discussion started by: nikhil jain
22 Replies

2. Shell Programming and Scripting

How to find arcsin for a coulmn containg values?

Hello everzone, I have a column of values and i need to find arcsin for evry value in this column. I am very new to shell scripting and would be glad to receive any help regarding this. Also i want them to be saved in the next column. Desired output: # # a arcsin(a) b arcsin(b) c ... (10 Replies)
Discussion started by: dinesh.n
10 Replies

3. UNIX for Dummies Questions & Answers

Print row wise

Hi Help, I have an I/p, which looks like --- FF GG HH I want the o/p to be like --- FF GG HH. How we can do that? Thanks (7 Replies)
Discussion started by: Indra2011
7 Replies

4. Shell Programming and Scripting

Pair wise comparisons

Hi, I have 25 groups and I need to perform all possible pairwise compariosns between them using the formula n(n-1)/2. SO in my case it will be 25(25-1)/2 which is equal to 300 comparisons. my 25 groups are FG1 FG2 FG3 FG4 FG5 NT5E CD44 CD44 CD44 AXL ADAM19 CCDC80 L1CAM L1CAM CD44... (1 Reply)
Discussion started by: Diya123
1 Replies

5. Shell Programming and Scripting

simple script ok=1 then go other wise no go

hello all, I have a simple script that i am trying to learn this off from...i am an oracle DBA.... here is the script... cat b.sh . oraenv cd $ORACLE_HOME echo $ORACLE_HOME echo 'TYPE 1 TO PROCESS OR 2 TO STOP' echo '1 OR 2' read ok if ok=1; then echo 'you provided YES answer to... (2 Replies)
Discussion started by: abdul.irfan2
2 Replies

6. Shell Programming and Scripting

perform some operation on a specific coulmn starting from a specific line

I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. eg: 50.000000 1 1 1 1000.00000 1000.00000 50000.000 19 19 3.69797533E-07 871.66394 ... (3 Replies)
Discussion started by: shashi792
3 Replies

7. UNIX for Dummies Questions & Answers

du -k . display size wise

Hi, I want to display all the directories with ascending order in size. For example, $ du -k . 1111111 ./dir1 222222222 ./dir2 333333333 ./dir3 444444444 ./dir4 How do i get the above desired result with du -k . command? Thanks (1 Reply)
Discussion started by: welldone
1 Replies

8. Shell Programming and Scripting

replace value with double quotes of specific coulmn value in csv file

Hi, I am trying to replace a specific column values in a csv file with double quotes. Example: SNO,NAME,ZIPCODE,RANK 1,Robert,74538,12 2,Sam,07564,13 3,Kim, Ed,12345,14 Desired Output: SNO,NAME,ZIPCODE,RANK 1,Robert Ken,74538,12 2,Sam Mik,"07564",13 3,"Kim, Ed",12345,14 I... (3 Replies)
Discussion started by: techmoris
3 Replies

9. Shell Programming and Scripting

o/p column wise by nawk

hi i have file which hav following entries 1501,AAA,2.00 1525,AAA,2.00 1501,AAA,2.00 1525,AAA,2.00 1501,AAA,3.00 1525,AAA,3.00 1525,AAA,3.00 1501,AAA,3.00 1501,AAA,3.00 i want to have a o/p coloum wise like 1501,AAA,13 1525,AAA,10 here 13 comes as a sum of last colum value... (6 Replies)
Discussion started by: aaysa123
6 Replies

10. Shell Programming and Scripting

How to merge different coulmn of differnt files

hello gurus , i want to merge different column from two different file. file struture is below. file 1 ------- ~information is given Name class section A 5 b B 7 C D 8 A file 2 (10 Replies)
Discussion started by: rahul sharma11
10 Replies
Login or Register to Ask a Question