The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bc and wc utilities??? skyineyes UNIX for Dummies Questions & Answers 6 05-29-2008 09:46 AM
Awk Utilities jyo123.jyothi Oracle Updates (RSS) 0 05-08-2008 01:19 AM
version of the utilities abey HP-UX 3 02-10-2006 03:39 AM
compression utilities jalburger UNIX for Dummies Questions & Answers 6 07-08-2004 08:06 AM
Zmodem Utilities SmartJuniorUnix UNIX for Dummies Questions & Answers 1 06-12-2001 07:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
Question Awk Utilities

Hi,
My input file is like this
1 11110001 1.1.1.1.1
2 12222212 2.3.44.5.6
3 22223333 1.3.2.4.1.55

Now i need the 2nd column value get printed
I tried with the following command
awk 'NR==1 {print $2}' input

this works fine for only 1st row.I need to change always NR assigned value to get printed all the 2nd column values so i tried like this but i m not getting

for( i=1;i<=3;i++)
do
Index=`awk 'NR==$i print $2}' input`
echo $Index

But i am not getting any value printed
Reply With Quote
Forum Sponsor
  #2  
Old 05-08-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
It works fine for me to do
awk '{print $2}' filename
Reply With Quote
  #3  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
Thanks for ur help but I actually need 1st row's 2nd column value.Like in the input file i need only 11110001 to be printed ,then after 1 iteration it should print 2nd row 2nd column value then 3rd row 2nd column value
Reply With Quote
  #4  
Old 05-08-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
I'm not shure if I understand your question, but the command I gave you will give you this output:

11110001
12222212
22223333

Is'nt this what you are trying? Else show the output you want.
Reply With Quote
  #5  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
see
Index=`awk 'NR==1 print $2}' input`
value=Index+3000

so the output will be 11113001
Like this it has to use for all the rows one by one

similar to this
for(i=1;i<=3;i++)
do
Index=`awk 'NR==$i print $2}' input`
value=Index+3000
echo $value
done
Reply With Quote
  #6  
Old 05-08-2008
Registered User
 

Join Date: Mar 2006
Location: Mumbai
Posts: 67
If the value 3000 remains same for all the iterations then
Code:
awk '{ print $2+3000 }' file
Reply With Quote
  #7  
Old 05-08-2008
Registered User
 

Join Date: Apr 2008
Posts: 11
Actually i need the value of 1st row and 2nd column once i.e 11110001 and do a set of operations on that value .I gave just example of adding 3000 but i have set of operations using that value.Then after all operations done it has iterate by itself and give the 2nd row 2nd column value to perform the set of operations .Then the 3rd row 3rd column...please give me the suggestion on how to capture one by one

Last edited by jyo123.jyothi; 05-08-2008 at 02:13 AM. Reason: Grammar
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0