LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-25-2011, 11:40 AM   #1
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Rep: Reputation: Disabled
Question Allignment of column data.


Hi,

i have file called B.txt which has data in columns like below.

Code:
:
"Gltbls_Data_02"         2097662        2.0004863739       1846783              1.7612295151           250879            .2392568588
"Gltbls_Index"         262158        .2500133514       229727           .2190847397           32431            .0309286118
"ProcDetl_Data"         511        .0004873276       511                .0004873276           0            0
i have to add heading and like below and add the above file B.txt to A.txt (heading) but allignment is not coming properly i tried awk for it. awk command is below.

can any body help.
Code:
:

awk '{if ($4 > ($2 * 0.85)) print $1 "         " $2 "        " $3 "       " $4 "\t \t" $5 "           " $6 "            " $7 }' < file
Code:
:
echo "    AreaName  MaxBlocks MaxBlocks(MB) CurrHiWaterMrk CurrwaterMrk(MB)  FreeBlks    FreeBlks(MB) " > A.txt
echo "======================================================================================================================================= " >> A.txt
        cat B.txt >> A.txt
 
Old 11-25-2011, 11:51 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,961

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by Sha_unix View Post
Hi,
i have file called B.txt which has data in columns like below. i have to add heading and like below and add the above file B.txt to A.txt (heading) but allignment is not coming properly i tried awk for it. awk command is below.

can any body help.
You've BEEN helped with this same issue, twice before:
http://www.linuxquestions.org/questi...a-file-915183/
http://www.linuxquestions.org/questi...olaris-914948/

You've been given the commands, structure, and lots of guidance. It's now time for YOU to take those things, and make them fit in your environment. If the alignment is off, have you tried reading the man pages for the commands? Exploring options on your own?? Perhaps trying to figure out how to make the solutions you've been given, work for your exact situation??

Asking folks over and over to tweak commands that you've already got, to give you what you want, doesn't show alot of effort on your part. The awk statements that colucix gave you will work. Take the tools you've been given, and THINK about how to get it to do what you want.
 
Old 11-25-2011, 12:17 PM   #3
Sha_unix
Member
 
Registered: Sep 2011
Posts: 46

Original Poster
Rep: Reputation: Disabled
Hi TB0ne,

my doubt was not that, the above links what you have provided will not provide the answer. that is totally different. And i am asking the doubts after i am scratching my head for hours.. i know tat if ask all the things i wont learn anything.

Anyway thank for your advice.

My doubt was hot to allign a data in a file. which looks like below.

Code:
"Gltbls_Data_02"         2097662        2.0004863739       1846783              1.7612295151           250879            .2392568588
"Gltbls_Index"         262158        .2500133514       229727           .2190847397           32431            .0309286118
"ProcDetl_Data"         511        .0004873276       511                .0004873276           0            0
 
Old 11-25-2011, 12:43 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,961

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by Sha_unix View Post
Hi TB0ne,
my doubt was not that, the above links what you have provided will not provide the answer. that is totally different. And i am asking the doubts after i am scratching my head for hours.. i know tat if ask all the things i wont learn anything.

Anyway thank for your advice. My doubt was hot to allign a data in a file. which looks like below.

Code:
"Gltbls_Data_02"         2097662        2.0004863739       1846783              1.7612295151           250879            .2392568588
"Gltbls_Index"         262158        .2500133514       229727           .2190847397           32431            .0309286118
"ProcDetl_Data"         511        .0004873276       511                .0004873276           0            0
The word "doubt" and the word "question" are two different things, and please spell out your words. And the previous two questions you asked ARE the same things...you asked how to add a heading, and how to align columns. Which is EXACTLY what you're asking here. Again, you use awk with formatted printing, and were told how to use either sed or cat commands to insert a header, in your other thread:
http://www.linuxquestions.org/questi...olaris-914948/

Very first hit in Google, after typing in "awk formatted output":
http://osr507doc.sco.com/en/OSUserG/...wk_output.html

Now, let's examine what you've been told:
  • You know how to insert a header into a file via various methods (cat, sed, etc.)
  • You know how to use awk to format output
So...use formatted awk output and either pipe it into sed or use the ">>" to get the header into a file (see replies in your other thread), then use the same formatted awk output command to get the rest of your data into the file. Again, read the pages on how to use awk to output formatted text, as you've been directed to. If you are ALREADY getting formatted output, but it's not lining up the way you want it to...CHANGE IT.

If the input text is already formatted (but incorrectly), you'll have to fix it first, which brings us back to the formatted awk output. Pumping B.txt through awk will re-format it the way you want. Which takes us back to your previous thread, which will tell you how to put the header onto that formatted file.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cut column an edit data!!!!! jacky29 Programming 6 03-26-2011 06:53 AM
Replace data of one column with data on other file corresponding to transaction ID saurabhmehan Linux - Newbie 1 12-23-2010 02:19 AM
script to change column data linuxquestion Programming 13 05-15-2010 10:26 AM
making two column-data ovince Programming 15 03-11-2007 08:24 AM
about LaTex footnotes allignment legolin Programming 2 11-01-2004 03:48 PM


All times are GMT -5. The time now is 10:38 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration