![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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 ========== Thanks, Karthikeyan. ========== |
|
|||
|
Edit: Do not try this code, it's got a couple of errors. See below for corrected version.
Quote:
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. |
|||
| Google The UNIX and Linux Forums |