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
display the result of wc -l with words before and after the result melanie_pfefer UNIX for Dummies Questions & Answers 3 04-30-2008 04:33 AM
AWK set FILENAME via user input timj123 Shell Programming and Scripting 2 02-24-2008 11:05 AM
awk user input gefa Shell Programming and Scripting 17 10-30-2007 01:01 AM
Getting user input stevefox Shell Programming and Scripting 3 02-15-2007 10:09 PM
Display result one page at a time nickaren UNIX for Dummies Questions & Answers 4 09-09-2003 10:15 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2008
Posts: 13
display result from user input

how can i only display the result according to user input?

For example:
i have a data file(in the attachement), when the user enter "1" it will only display whole records with pid from the data file matches to the users entered.
Attached Files
File Type: txt tes.txt (198 Bytes, 16 views)
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-30-2008
Registered User
 

Join Date: Jan 2007
Location: Boston, USA
Posts: 16
Thumbs up Try this....

Try the below code.
Code:
echo "Enter the PID :"
read pid
linenum=`cat tes.txt | tr -s " " "|" | cut -d"|" -f2 |grep -n $pid`
cat tes.txt | head -$linenum | tail -1
Its giving the expected results.


==========
Thanks,
Karthikeyan.
==========
Reply With Quote
  #3 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 13
hi Karthikeyan_113! i have error when i run the code.

error shown:
head: unrecongonized option `-:'
Reply With Quote
  #4 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 309
Does it have to be awk/ksh? Can you use perl?
Reply With Quote
  #5 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,543
Code:
awk 'BEGIN{
 printf "%s : " ,"What Pid"
 getline pid <"-" 
}
$1==pid'  "file"
Reply With Quote
  #6 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,543
Quote:
Originally Posted by KevinADC View Post
Does it have to be awk/ksh? Can you use perl?
you could just post your Perl solution. If OP wants a Perl solution, he will use it.
Reply With Quote
  #7 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Posts: 309
Edit: Do not try this code, it's got a couple of errors. See below for corrected version.


Quote:
Originally Posted by ghostdog74 View Post
you could just post your Perl solution. If OP wants a Perl solution, he will use it.
You're right mate. I am not sure what he wants printed out, the whole line or just part of the data, but this prints the whole line associated with the PID number:

Code:
use strict;
use warnings;
print "Enter the PID :"
my $pid = <STDIN>;
chomp $pid;
open (IN , "tes.txt");
while (<IN>) {
   print if (/^\s*$pid\s/); 
   last;
}
close IN;
exit;

Last edited by KevinADC; 01-31-2008 at 02:43 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, ubuntu

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:13 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 Global Fact Book

Content Relevant URLs by vBSEO 3.2.0