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
perl script to print to values in rows and columns nogu0001 Shell Programming and Scripting 3 02-22-2009 04:30 PM
awk - reformating rows into columns jmd2004 Shell Programming and Scripting 1 08-13-2008 11:56 PM
How to changes rows to columns in a file oracle123 Shell Programming and Scripting 4 07-31-2008 04:38 AM
compare columns from seven files and print the output smriti_shridhar Shell Programming and Scripting 7 06-11-2008 12:22 AM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 07:03 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 04-21-2009
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
want to print output if u have rows and columns

U have a file
File 1
0.3 0.2 0.4 0.3 0.8 0.11 0.22
0.4 0.23 0.45 0.56 0.78 0.98
0.11 0.32 0.2 0.4 0.45 0.54
0.2 0.33 0.44 0.21 0.22 0.98
0.8 0.2 0.34 0.54 0.98 0.12
0.1 0.22 0.32 0.34 0.89 0.22


File 2
rows columns
3 1
2 3
4 2
5 5

so from file 2 into file 1
output will be
0.11
0.45
0.2
0.89

I have used using awk

awk -v num=3 '{if(NR==num) print($0);}' File1 | awk '{print $1}'

awk -v num=2 '{if(NR==num) print($0);}' File1 | awk '{print $3}

Now problem is it is long manual process as it is having big file

So any done using perl or shell script..????

Last edited by cdfd123; 04-23-2009 at 12:50 AM.. Reason: check in file 1
  #2 (permalink)  
Old 04-21-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
awk '{ printf "NR == %d { print $%d }\n", $1, $2 }' File2 |
 awk -f - File1
  #3 (permalink)  
Old 04-21-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Nice one

And another one, assuming typos in your example output:
(use gawk, nawk or /usr/xpg4/bin/awk on Solaris)
Code:
awk 'NR == FNR { _[$1] = $2; next }
FNR in _ { print $_[FNR] }' File2 File1
  #4 (permalink)  
Old 04-23-2009
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Post some awk error??

Thanks for the reply
But after running the program the output is
0.45
0.11
0.33
0.98

But is shud be
0.11
0.45

0.33
0.98
  #5 (permalink)  
Old 04-23-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Would you mind to explain the logic behind?
  #6 (permalink)  
Old 04-23-2009
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
output in order wise

Quote:
Originally Posted by radoulov View Post
Would you mind to explain the logic behind?
Dear Radulov,
actually overall output was right in using this awk command but in random order as u can see in output
first one came as second order and second came as first as a large file is there it is confusing where it is ? But command wise is right

Another latest reply is giving right answer in orderwise

Thanks
  #7 (permalink)  
Old 04-23-2009
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...
Code:
awk 'FNR==NR{for(i=1;i<=NF;i++)a[NR,i]=$i;next}{print a[$1,$2]}' file1 file2
...gives...
0.11
0.45
0.33
0.98
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:00 PM.


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