![]() |
|
|
|
|
|||||||
| 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 12:05 PM |
| awk user input | gefa | Shell Programming and Scripting | 17 | 10-30-2007 02:01 AM |
| Getting user input | stevefox | Shell Programming and Scripting | 3 | 02-15-2007 11: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 |
|
#1
|
|||
|
|||
|
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 | ||
|
|
|
#2
|
|||
|
|||
|
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. ========== |
|
#3
|
|||
|
|||
|
hi Karthikeyan_113! i have error when i run the code.
error shown: head: unrecongonized option `-:' |
|
#4
|
|||
|
|||
|
Does it have to be awk/ksh? Can you use perl?
|
|
#5
|
|||
|
|||
|
Code:
awk 'BEGIN{
printf "%s : " ,"What Pid"
getline pid <"-"
}
$1==pid' "file"
|
|
#6
|
|||
|
|||
|
you could just post your Perl solution. If OP wants a Perl solution, he will use it.
|
|
#7
|
|||
|
|||
|
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 03:43 AM. |
|||
| Google The UNIX and Linux Forums |