Sponsored Content
Top Forums Shell Programming and Scripting matching user input to a text file loop? Post 302577327 by Chubler_XL on Monday 28th of November 2011 06:23:22 PM
Old 11-28-2011
Assumption: Your trying to validate user input against a list of valid responses (in cars_names.txt).

Code:
read -p "Car: " cars1
until grep -wiq "$cars1" cars_names.txt && [ -n "$cars1" ]
do
   echo "Invalid car. Try again"
   read -p "Car: " cars1
done


Last edited by Chubler_XL; 11-28-2011 at 07:26 PM.. Reason: Added trap for empty response
This User Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

read user input from within a wile loop that is being fed from below

hi! i need to do a ksh script that uses a wile loop that is fed form below while read line do some things done < myfile inside the while loop i need to read user input to ask the user what he wants to do, but "read" reads the file, and not the standard input while read line do ... (2 Replies)
Discussion started by: broli
2 Replies

2. Shell Programming and Scripting

Loop until user input is correct

Hello, i know how to retrieve a user input (read), and how to manage the different options (case statement). But... could anybody show me a script that, if the user option is incorrect, don't allow to continue the excution, i.e., if the value entered is not 1 or 2, the script shows a question. ... (2 Replies)
Discussion started by: aristegui
2 Replies

3. UNIX for Dummies Questions & Answers

Replacing part of a text file with user input.

Ok, I am brand new to UNIX and I am trying to learn a cross between basic script and database use. I had got some ideas off the net on simple ideas for learning UNIX. I am working on creating a simple phone book program that allows myself to enter our employees from work into a phone book text... (0 Replies)
Discussion started by: georgefurbee
0 Replies

4. UNIX for Dummies Questions & Answers

Getting user input from inside a while loop?

I'm new to BASH and i'm trying to create a script which is simply put a large find and replace file. This is what I have so far N=0 while read LINE ; do N=$((N+1)) sed 's/'$2'/'$3'/g' $LINE > .temp echo "Changes to file $N = $LINE" echo 'The following changes... (5 Replies)
Discussion started by: Azumandious
5 Replies

5. UNIX for Dummies Questions & Answers

How to read a line of text from user input?

Hiii I wanna a read a line of text from standard input. The user enter data like this way name phone_no month1_salary month2_salary that is user enter the name ,phone no and salary of 2 months in a single line by giving spaces. I wanna add the 3rd and 4th fields ...ie add both... (4 Replies)
Discussion started by: krishnampkkm
4 Replies

6. Shell Programming and Scripting

Input file line matching

Hi there, I have two input files. I need to match the last two columns of each line in File1 with the first two columns of a line in File2. Example: File1 AAA BB 234 789 BBB CC 426 624 CCC DD 356 643 File2 766 332 12 234 789 64 122 633 23 426 624 88 777 453 22 356 643 92 ... (3 Replies)
Discussion started by: palex
3 Replies

7. Shell Programming and Scripting

no chance to input passwd when create new user in loop

Hi Dears, I have one script to create new users with information in one plain text file. This script will read all lines in the file and create one users for one line. Sample file: #action;login,full name title,expire date,project +;gmwen,Bruce Wen QA,04/01/2012,BT +;xxdeng,Shown Deng... (4 Replies)
Discussion started by: crest.boy
4 Replies

8. Shell Programming and Scripting

Loop breaks on yes/no user input

I have a shell script, and its pretty much done, I decided to add a loop that ends or continues depending on user input. like "would you like to continue?" and if I hit y or yes it will run the loop again until I hit n or no and breaks out of the loop. To be hones I didn't think I needed to add... (2 Replies)
Discussion started by: Demon_Jester
2 Replies

9. Shell Programming and Scripting

Unable to read user input inside a loop

Hi, This query is a part of a much more lengthy script. I wish to look for all the files in a folder named "data" which in this case has two files i.e. plan.war and agent.properties. For all the files found under data I wish to ask the user as to where they wish copy the files to. Below,... (14 Replies)
Discussion started by: mohtashims
14 Replies

10. Shell Programming and Scripting

Would like to check user input for letters within a loop

Hi All, #!/bin/bash #Just trying to check if letters are in the user input. Any tips? # I have tried regexp and using 0-9 etc, i cannot get this to work either in just an if statement or while in a loop. echo "Please pick a number" read num if ; then echo "Please enter a number"... (7 Replies)
Discussion started by: jvezinat
7 Replies
GRAPH-EASY(1p)						User Contributed Perl Documentation					    GRAPH-EASY(1p)

NAME
graph-easy - render/convert graphs in/from various formats SYNOPSIS
Convert between graph formats and layout/render graphs: graph-easy [options] [inputfile [outputfile]] echo "[ Bonn ] - car -> [ Berlin ]" | graph-easy graph-easy --input=graph.dot --as_ascii graph-easy --html --output=mygraph.html graph.txt graph-easy graph.txt graph.svg graph-easy graph.txt --as_dot | dot -Tpng -o graph.png graph-easy graph.txt --png graph-easy graph.vcg --dot graph-easy graph.dot --gdl graph-easy graph.dot --graphml ARGUMENTS
Here are the most important options, more are listed in the full documentation: --help Print the full documentation, not just this short overview. --input Specify the input file name. Example: graph-easy --input=input.txt The format will be auto-detected, override it with --from. --output Specify the output file name. Example: graph-easy --output=output.txt input.txt --as Specify the output format. Example: graph-easy --as=ascii input.txt Valid formats are: ascii ASCII art rendering boxart Unicode Boxart rendering html HTML svg Scalable Vector Graphics graphviz the DOT language dot alias for "graphviz" txt Graph::Easy text vcg VCG (Visualizing Compiler Graphs - a subset of GDL) text gdl GDL (Graph Description Language) text graphml GraphML In addition, the following formats are understood and piped through the program specified with the --renderer option (default: dot): bmp Windows bitmap gif GIF hpgl HP-GL/2 vector graphic jpg JPEG pcl PCL printer language pdf PDF png PNG ps Postscript ps2 Postscript with PDF notations (see graphviz documentation) tga Targa bitmap tif TIFF bitmap The default format will be determined by the output filename extension, and is "ascii", if the output filename was not set. You can also use ONE argument of the form "--as_ascii" or "--ascii". --from Specify the input format. Valid formats are: graphviz the DOT language txt Graph::Easy text vcg VCG text gdl GDL (Graph Description Language) text If not specified, the input format is auto-detected. You can also use ONE argument of the form "--from_dot", etc. --renderer The external program (default: "dot") used to render the output formats like "png", "jpg" etc. Some choices are "neato", "twopi", "fdp" or "circo". --parse Input will only be parsed, without any output generation. Useful in combination with "--debug=1" or "--stats". Example: graph-easy input.txt --parse --debug=1 --stats Write various statistics about the input graph to STDERR. Best used in combination with "--parse": graph-easy input.txt --parse --stats --timeout Set the timeout in seconds for the Graph::Easy layouter that generates ASCII, HTML, SVG or boxart output. If the layout does not finish in this time, it will be aborted. Example: graph-easy input.txt --timeout=500 Conversion to DOT, VCG/GDL, GraphML or plain text ignores the timeout. The default is 240 seconds (4 minutes). --verbose Write info regarding the conversion process to STDERR. DESCRIPTION
"graph-easy" reads a description of a graph (a connected network of nodes and edges, not a pie chart :-) and then converts this to the desired output format. By default, the input will be read from STDIN, and the output will go to STDOUT. The input is expected to be encoded in UTF-8, the output will also be UTF-8. It understands the following formats as input: Graph::Easy http://bloodgate.com/perl/graph/manual/ DOT http://www.graphviz.org/ VCG http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html GDL http://www.aisee.com/ The formats are automatically detected, regardless of the input file name, but you can also explicitly declare your input to be in one specific format. The output can be a dump of the graph in one of the following formats: Graph::Easy http://bloodgate.com/perl/graph/manual/ DOT http://www.graphviz.org/ VCG http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html GDL http://www.aisee.com/ GraphML http://graphml.graphdrawing.org/ In addition, "Graph::Easy" can also create layouts of graphs in one of the following output formats: HTML SVG ASCII BOXART Note that for SVG output, you need to install the module Graph::Easy::As_svg first. As a shortcut, you can also specify the output format as 'png', this will cause "graph-easy" to pipe the input in graphviz format to the "dot" program to create a PNG file in one step. The following two examples are equivalent: graph-easy graph.txt --dot | dot -Tpng -o graph.png graph-easy graph.txt --png OTHER ARGUMENTS
"graph-easy" supports a few more arguments in addition to the ones from above: --version Write version info and exit. --debug=N Set the debug level (1..3). Warning, this will generate huge amounts of hard to understand output on STDERR. Example: graph-easy input.txt --output=test.html --debug=1 --png, --dot, --vcg, --gdl, --txt, --ascii, --boxart, --html, --svg Given exactly one of these options, produces the desired output format. EXAMPLES
ASCII output echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy +--------+ car +-----+ | Bonn | -----> | Ulm | +--------+ +-----+ | | car v +--------+ | Berlin | +--------+ Graphviz example output echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy --dot digraph GRAPH_0 { edge [ arrowhead=open ]; graph [ rankdir=LR ]; node [ fontsize=11, fillcolor=white, style=filled, shape=box ]; Bonn -> Ulm [ label=car ] Bonn -> Berlin [ label=car ] } VCG example output echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy --vcg graph: { title: "Untitled graph" node: { title: "Berlin" } node: { title: "Bonn" } node: { title: "Ulm" } edge: { label: "car" sourcename: "Bonn" targetname: "Ulm" } edge: { label: "car" sourcename: "Bonn" targetname: "Berlin" } } GDL example output GDL (Graph Description Language) is a superset of VCG, and thus the output will look almost the same as VCG: echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy --gdl graph: { title: "Untitled graph" node: { title: "Berlin" } node: { title: "Bonn" } node: { title: "Ulm" } edge: { label: "car" source: "Bonn" target: "Ulm" } edge: { label: "car" source: "Bonn" target: "Berlin" } } GraphML example output GraphML is XML: echo "[ Bonn ] -- car --> [ Berlin ], [ Ulm ]" | graph-easy --graphml <?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"> <!-- Created by Graph::Easy v0.58 at Mon Aug 20 00:01:25 2007 --> <key id="d0" for="edge" attr.name="label" attr.type="string"/> <graph id="G" edgedefault="directed"> <node id="Berlin"> </node> <node id="Bonn"> </node> <node id="Ulm"> </node> <edge source="Bonn" target="Berlin"> <data key="d0">car</data> </edge> <edge source="Bonn" target="Ulm"> <data key="d0">car</data> </edge> </graph> <graphml> CAVEATS
Please note that it is impossible to convert 100% from one format to another format since every graph language out there has features that are unique to only this language. In addition, the conversion process always converts the input first into an Graph::Easy graph, and then to the desired output format. This means that only features and attributes that are actually valid in Graph::Easy are supported yet. Work in making Graph::Easy an universal format supporting as much as possible is still in progress. Attributes that are not yet supported natively by Graph::Easy are converted to custom attributes with a prefixed "x-format-", f.i. "x-dot-". Upon output to the same format, these are converted back, but conversion to a different format will lose these attributes. For a list of what problems still remain, please see the TODO file in the "Graph::Easy" distribution on CPAN: http://search.cpan.org/~tels/Graph-Easy/ <http://search.cpan.org/~tels/Graph-Easy/> If you notice anything wrong, or miss attributes, please file a bug report on http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-Easy <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-Easy> so we can fix it and include the missing things into Graph::Easy! LICENSE
This library is free software; you can redistribute it and/or modify it under the terms of the GPL. See the LICENSE file of Graph::Easy for a copy of the GPL. This product includes color specifications and designs developed by Cynthia Brewer (<http://colorbrewer.org/>). See the LICENSE file for the full license text that applies to these color schemes. AUTHOR
Copyright (C) 2004 - 2008 by Tels <http://bloodgate.com> SEE ALSO
More information can be found in the online manual of Graph::Easy: <http://bloodgate.com/perl/graph/manual/> See also: Graph::Easy, Graph::Easy::Manual perl v5.14.2 2011-12-23 GRAPH-EASY(1p)
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy