Visit Our UNIX and Linux User Community

display result from user input

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display result from user input
# 1  
Old 01-31-2008
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.
# 2  
Old 01-31-2008
MySQL Try this....

Try the below 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.

# 3  
Old 01-31-2008
hi Karthikeyan_113! i have error when i run the code.

error shown:
head: unrecongonized option `-:'
# 4  
Old 01-31-2008
Does it have to be awk/ksh? Can you use perl?
# 5  
Old 01-31-2008
awk 'BEGIN{
 printf "%s : " ,"What Pid"
 getline pid <"-" 
$1==pid'  "file"

# 6  
Old 01-31-2008
Originally Posted by KevinADC
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.
# 7  
Old 01-31-2008
Edit: Do not try this code, it's got a couple of errors. See below for corrected version.

Originally Posted by ghostdog74
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:

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

Last edited by KevinADC; 01-31-2008 at 07:43 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #615
Difficulty: Medium
You can specify multi-line strings using triple quotes in Python.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to parse file and display result based on text

I am trying using awk to open an input file and check a column 2/field $2 and if there is a warning then that is displayed (variantchecker): G not found at position 459, found A instead. The attached Sample1.txt is that file. If in that column/field there is a black space, then the text after... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. UNIX for Dummies Questions & Answers

Japanese layout input. Help to get result with uim? (X)

It's easy but I'm searching how to work with fonts (besides) emerging them. /etc/conf.d/consolefont (consolefont=" ") - what to write after install, m.b. paths are wrong (emerged /usr/share/fonts/efont-unicode/*.gz). Has it any relation to X11 hieroglyph input?:wall: (1 Reply)
Discussion started by: Xcislav
1 Replies

3. Shell Programming and Scripting

Bash script to display result in table

My script gives the following result. Is it possible to display the same in table format ? 1. rex_best Latest feeds are not avaialable. The last feed was generated on 2012-05-17 File Name = ekb_best_20120517_010949_665.tar.gz The Number of entry elements = 4209539 2. rex_genre Latest... (2 Replies)
Discussion started by: kishorekumar87
2 Replies

4. Shell Programming and Scripting

display Range of date depend on user input php

Hi, i am very new to php Is it possible to display Range of date depend on user input day example: user input 2 day start from 28/4/12 it will add 2 day from date of input so display should look like this 28/4/12 to 30/4/12 then from 30/412 user add another 4 date so will... (0 Replies)
Discussion started by: guidely
0 Replies

5. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

6. UNIX for Dummies Questions & Answers

How to display values from user input array?

Hi all, I wrote a script that reads inputs from user and store in array named "input". The number of elements in the array is not fixed - determined only after user exit the while loop that reads the array values : x=1 echo "Enter first value" read input while } != "exit" ] do ... (1 Reply)
Discussion started by: luna_soleil
1 Replies

7. Shell Programming and Scripting

csh script to search for files and display result

Hello all. I'm a long time browser, first time poster...Be gentle :-) I don't use csh much, but have been asked to make a small script for our HP-UX systems to search for a report file(s) or summary file and display the result (I was using vuepad, but this probably is just complicating... (4 Replies)
Discussion started by: neillsm
4 Replies

8. Shell Programming and Scripting

Pick up the return code for every iteration and display the result only once in loop.

Hi All, I amlearning UNIX scripting. I have a small query. I would be thankful if any one helps me out. I have a below piece of code which delets the files. If file dosent have the permissions to delete a particular file I have used 2>>operator to track the error code. But my objective is... (1 Reply)
Discussion started by: manas6
1 Replies

9. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

10. UNIX for Dummies Questions & Answers

Display result one page at a time

hi how can i display the result on the screen one page at a time? say i search for .txt files and return the result on the screen one page at a time. (4 Replies)
Discussion started by: nickaren
4 Replies

Featured Tech Videos