The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to open program and send/execute command in program tuathan UNIX for Dummies Questions & Answers 1 11-19-2008 09:59 PM
A program to trace execution of another program jiten_hegde High Level Programming 3 08-19-2008 05:26 AM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 05:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 01:44 PM
executing a program within a program Gekko High Level Programming 4 06-27-2002 03:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2009
aaaaargh aaaaargh is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 20
Code:
awk '{printf "%s ",$5} ' file*  |   tr ' ' '\n' | while read a; do read b; echo "$a $b"; done
  #2 (permalink)  
Old 03-19-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Quote:
Originally Posted by aaaaargh View Post
Code:
awk '{printf "%s ",$5} ' file*  |   tr ' ' '\n' | while read a; do read b; echo "$a $b"; done
i don't think this will work
  #3 (permalink)  
Old 03-19-2009
wabard wabard is offline
Registered User
  
 

Join Date: Mar 2009
Location: Adelaide, SA & Perth, WA - Australia
Posts: 25
Exclamation

Sorry for the late reply (meetings... )

(assume awkscript filename = SmellsLikeHomeWork.awk)

Code:

{
  if (c!=FILENAME) { c=FILENAME ; i++ ;j=0 }
  a[i,++j] = $5
}


END {
    for( n=1 ; n<=j ; n++)
    {
      for( m=1 ; m<=i ; m++ )
      {
        printf("%s ",a[m,n]);
      }
      printf("\n");
    }
}
Usage: nawk -f SmellsLikeHomeWork.awk file1 file2 file3 file4
  #4 (permalink)  
Old 03-19-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
This should do:

Code:
awk '{print $5}' $(ls -1 file* |sort -n -k1.5) |pr -t -s" " -184
184 is the no. of files. The reason behind the "$(ls -1 file* |sort -n -k1.5)" is to get the files in correct alphabetical order (it skips 'file' and sorts on 1, 2, 3...). If your filenames are not following a regular pattern, then you may need to put them manually in the correct order like this:

Code:
awk '{print $5}' f1 file2 filename3 |pr -t -s" " -3
  #5 (permalink)  
Old 03-19-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
Thumbs up

Quote:
Originally Posted by rikxik View Post
This should do:

Code:
awk '{print $5}' $(ls -1 file* |sort -n -k1.5) |pr -t -s" " -184
184 is the no. of files. The reason behind the "$(ls -1 file* |sort -n -k1.5)" is to get the files in correct alphabetical order (it skips 'file' and sorts on 1, 2, 3...). If your filenames are not following a regular pattern, then you may need to put them manually in the correct order like this:

Code:
awk '{print $5}' f1 file2 filename3 |pr -t -s" " -3

great.. i couldn't remember that "pr" command
  #6 (permalink)  
Old 03-19-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250
I don't think its used often but sometimes its just what you need.
  #7 (permalink)  
Old 03-19-2009
awkliker awkliker is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 6
Thanks!

Thanks to you all for working so hard to help me!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0