The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
paste several files tonet Shell Programming and Scripting 1 10-05-2007 07:08 AM
paste 2 files ( it is possible???) mig28mx UNIX for Dummies Questions & Answers 3 06-21-2007 08:51 AM
Paste the files contents differently er_aparna Shell Programming and Scripting 1 05-16-2007 01:29 AM
Need a Help with paste 2 files since the output is not what i want alexcol Shell Programming and Scripting 3 01-09-2007 12:47 AM
awk or sed or paste leprichaun UNIX for Dummies Questions & Answers 3 11-16-2003 03:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 08-04-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,804
Stumble this Post!
Code:
paste one two three four five six seven eight nine ten eleven twelve > tmp
paste tmp thirteen > final_file
This is what drl told and others told you about a tmp file.
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 08-04-2008
Registered User
 

Join Date: Jan 2006
Posts: 145
Stumble this Post!
Thanks Jim!

I know this technique already. I am interested in:

somecommand file* (1 command line if possible no PIPE involve)

that will give me the results

1 2 3 4 5 6 7 8 9 10 11 12 13

can awk or some other commands be functioned as paste some how????

Thanks!
Reply With Quote
  #10 (permalink)  
Old 08-04-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 672
Stumble this Post!
Code:
awk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*
Reply With Quote
  #11 (permalink)  
Old 08-07-2008
Registered User
 

Join Date: Jan 2006
Posts: 145
Stumble this Post!
thanks for the reply but it is not working.
Example:

file1
cat file1
1

file2
cat file2
2
3

file3
cat file3
3
4

awk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*

result show nothing


try it with nawk

nawk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*

results:
1 2 3
3 4

I need the data:

1 2 3
3 4

Any takers????

Thanks!
Reply With Quote
  #12 (permalink)  
Old 08-07-2008
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 505
Stumble this Post!
Hi.
Quote:
Originally Posted by bobo View Post
thanks for the reply but it is not working ...

nawk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*

results:
1 2 3
3 4

I need the data:

1 2 3
3 4

Any takers????

Thanks!
To most observers those look exactly the same, hence the requirements are met.

However, what you apparently attempted to type was:
Code:
try it with nawk

nawk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*

results:
1 2 3
3 4

I need the data:

1   2   3
    3   4
There are 2 lessons to be learned here. For program and data, one needs to use CODE tags around the text. I think you've been around here long enough (100+ posts) to know and start using that.

Secondly, this last requirement was not in your initial requirements. As it turns out, both paste and paste.perl do the right thing with such files.

The awk will need to be augmented to supply a default string when it runs out of lines with your last example file1.

For my purposes, paste and paste.perl solve all the problems. Best wishes ... cheers, drl
Reply With Quote
  #13 (permalink)  
Old 08-07-2008
Registered User
 

Join Date: Jan 2006
Posts: 145
Stumble this Post!
i know how to use paste. I can't paste more then 12 files or more. That is why I tried to see any one have other solustions.

nawk '{l[FNR]=l[FNR] $0 OFS} FNR>max {max=FNR} END {for (i=1;i<=max;i++){print l[i]}}' file*

this command is not working
Reply With Quote
  #14 (permalink)  
Old 08-07-2008
Registered User
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 672
Stumble this Post!
Try this:

Code:
awk '
        FNR==1 { col++ }
        FNR>max { max=FNR }
        { l[FNR,col]=$0 }
        END {
                for (i=1;i<=max;i++) {
                        for (j=1;j<=col;j++) {
                                printf "%-10s",l[i,j]
                        }
                        print ""
                }
        }
' file*
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:28 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0