LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-21-2010, 05:58 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192

Thanks for the compliment

I did add a gensub in to take those spaces out but actually quite like the output as it was

I also tried adding:
Code:
if(_[FNR])
    _[FNR]=_[FNR] sprintf("%-8s",$2)
else
    _[FNR]=$2
But it comes out wonky because it is missing the length of the input and so agreed with you it would then become a lot more messy
 
Old 12-21-2010, 09:52 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Just an update -- turns out it was easier than I thought (change in red):
Code:
{
    while( length(_[FNR]) < ((ARGIND - 1) * 8))
        _[FNR]=_[FNR] sprintf("%8s","")

    _[FNR]=_[FNR] sprintf("%-8s",$2)
}

END{
    for(x=1; x < ARGC; x++)
        print _[x]
}
 
Old 01-25-2011, 10:59 PM   #18
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
How about this. Let me know if this is what you are looking for:

Joining Two Columns Using Bash
 
Old 01-26-2011, 05:04 AM   #19
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by ramram29 View Post
How about this. Let me know if this is what you are looking for:

Joining Two Columns Using Bash
that script is long winded and inefficient, making use of unnecessary external tools. You can easily use paste or just awk
Code:
awk '{getline a<"file2"; print a FS $0}' file1
or even just bash (don't use this method if file is large )

Code:
#!/bin/bash
exec 4<"file2"
while read -r LINE
do
  read L <&4
  echo $L $LINE
done <"file1"
exec 4<&-
 
Old 01-26-2011, 07:15 AM   #20
ramram29
Member
 
Registered: Jul 2003
Location: Miami, Florida, USA
Distribution: Debian
Posts: 848
Blog Entries: 1

Rep: Reputation: 47
Quote:
Originally Posted by ghostdog74 View Post
or even just bash (don't use this method if file is large )
What if the file "IS" very large? Then what? Do you think the external commands will be more useful then?
 
Old 01-26-2011, 09:35 AM   #21
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by ramram29 View Post
What if the file "IS" very large? Then what? Do you think the external commands will be more useful then?
it has been proven that external commands like awk works better on big files as compared to the shell's while read loop.

Last edited by ghostdog74; 01-26-2011 at 09:38 AM.
 
Old 06-24-2014, 06:59 AM   #22
pdsun
LQ Newbie
 
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
printing columns

Hi

Further modification into the code, i want to print starting 2 columns only for the first file while column two only for the remaining files. The concept is is to use the first column (from first file) as header for the remaining columns. Thanks for the help!!


Quote:
Originally Posted by grail View Post
Just an update -- turns out it was easier than I thought (change in red):
Code:
{
    while( length(_[FNR]) < ((ARGIND - 1) * 8))
        _[FNR]=_[FNR] sprintf("%8s","")

    _[FNR]=_[FNR] sprintf("%-8s",$2)
}

END{
    for(x=1; x < ARGC; x++)
        print _[x]
}
 
  


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
extracting columns from multiple files with awk orcaja Linux - Newbie 7 02-14-2012 10:24 PM
merge multiple pdf files esteeven Linux - Software 8 11-21-2007 01:59 PM
awk command to merge columns from two separate files into single file? johnpaulodonnell Linux - Newbie 4 01-23-2007 10:10 AM
How To Merge multiple files into a single PDF ? kkempter Linux - Software 1 10-28-2005 01:02 PM
Is there a command to merge two files as two columns of one file? davee Linux - General 2 07-19-2005 10:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:21 AM.

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