LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-27-2005, 09:48 AM   #1
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,958

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
awk column printing


hi lq,

i have this:
Code:
/temp> cat test.lst
rc00    rc01    rc02    hello
rc10    rc11    rc12    world
rc20    rc21    rc22    l33t
rc30    rc31    rc32    h4x0rz
rc40    rc41    rc42    chun-li
rc50    rc51    rc52    akuma
i want to end up with this:
Code:
/temp> cat test.lst
rc00    rc01    rc02    hello	hello	world	l33t	h4x0rz	chun-li	akuma
rc10    rc11    rc12    world	hello	world	l33t	h4x0rz	chun-li	akuma
rc20    rc21    rc22    l33t	hello	world	l33t	h4x0rz	chun-li	akuma
rc30    rc31    rc32    h4x0rz	hello	world	l33t	h4x0rz	chun-li	akuma
rc40    rc41    rc42    chun-li	hello	world	l33t	h4x0rz	chun-li	akuma
rc50    rc51    rc52    akuma	hello	world	l33t	h4x0rz	chun-li	akuma
basically all of the col4's are appended to the end of each line.

any suggestions... thanks,
 
Old 09-27-2005, 10:10 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
It doesn't use awk, but it's nice and simple:
Code:
sed 's/$/ hello world l33t h4x0rz chun-liakuma/g' test.lst
Edit: oops. didn't read the problem properly. Hold on...

Dave
 
Old 09-27-2005, 10:26 AM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
OK. I'd do it like this:
Code:
for GO in `awk '{print $4}' test.lst`
  do
  FOUR="$FOUR $GO"
done
sed 's/$/ '"$FOUR"'/g' test.lst
Dave
 
Old 09-27-2005, 10:58 AM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,958

Original Poster
Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
thx jam,
i'll play around with it.
i'll try not to 'forgo' your suggestion,

~schneidz
 
Old 09-27-2005, 12:38 PM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Ouch.
 
Old 09-28-2005, 09:17 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
this works in korn shell (ksh)

bash not.
bad bash, naughty bash

Code:
billym.primadtpdev>unset x;cat test.lst | while read a b c d; do  x="$x $d";done
billym.primadtpdev>cat test.lst | while read a;do echo $a $x;done
rc00 rc01 rc02 hello hello world l33t h4x0rz chun-li akuma
rc10 rc11 rc12 world hello world l33t h4x0rz chun-li akuma
rc20 rc21 rc22 l33t hello world l33t h4x0rz chun-li akuma
rc30 rc31 rc32 h4x0rz hello world l33t h4x0rz chun-li akuma
rc40 rc41 rc42 chun-li hello world l33t h4x0rz chun-li akuma
rc50 rc51 rc52 akuma hello world l33t h4x0rz chun-li akuma
 
Old 09-28-2005, 01:26 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,958

Original Poster
Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
Quote:
thx jam,
i'll play around with it.
i'll try not to 'forgo' your suggestion,
jam, were your variable name choices purposeful. because there are a lot of 'for go...' / '$four $go...' statements looked kinda like plain english but may have been coincedental.

naughty bash, huh billy.
we'll see...
 
Old 09-29-2005, 06:14 AM   #8
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
I always use 'GO' for loop counters. I think it's because you'd say "the loop did this on the fifth go".

The FOUR was because it's the fourth column.

Something like that anyway.

Dave
 
  


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
add id in the first column alaios Linux - General 1 11-19-2004 06:49 AM
How to delete a column in MySQL ? indian Linux - General 2 10-15-2004 01:02 PM
Column limit agallant Programming 1 08-05-2004 10:58 AM
132 column printing sachin_keluskar Linux - Software 0 07-17-2004 02:29 AM
add new column Eddie9 Linux - General 2 04-09-2002 12:05 PM


All times are GMT -5. The time now is 05:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration