Read 2 input and produce it in single ouput?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read 2 input and produce it in single ouput?
# 8  
Old 03-02-2015
You could add this to make it the loop stop for certain input, in this case a zero or no input at all (empty string):
Code:
while 
  printf "Enter new group name (enter 0 to stop): "
  read service_group
do
  printf "You entered: %s\n" "$service_group"
  case $service_group in
    0|"") break
  esac
  printf "create service_group %s\n" "$service_group"
  while read port
  do
    printf "create service_group %s '' services:tcp%s\n" "$service_group" "$port"
  done < file
done


Of course, if it always only needs to be executed once, then you can leave out the outer loop altogether:
Code:
printf "Enter new group name : "
read service_group
printf "You entered: %s\n" "$service_group"
printf "create service_group %s\n" "$service_group"
while read port
do
  printf "create service_group %s '' services:tcp%s\n" "$service_group" "$port"
done < file2

# 9  
Old 03-02-2015
Unless you add some tests for e.g. empty input or an "END" string entered, you can end the loop by end-of-file, which is CTRL-D.

CTRL-C is fine, btw.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read input from Keyboard, do not proceed if no input

Hi, I am working on a script, which requests users to enter input. Ex: read -p "Please enter your email id:" email I don't want users skipping this entry, this has to be mandatory.I dont want to proceed without input. I can do a check if variable $email is empty and proceed if not.But, i... (7 Replies)
Discussion started by: aravindadla
7 Replies

2. Shell Programming and Scripting

How do I split a single-line input into five lines?

Example input: John:Shepherd:770-767-4040:U.S.A:New York Mo Jo:Jo Jo: 666-666-6666:U.S.A:Townsville Expected Output: First Name: John Last Name: Shepherd Phone Number: 770-767-4040 Country: U.S.A State: New York First Name: Mo Jo Last Name: Jo Jo Phone Number: 666-666-6666... (10 Replies)
Discussion started by: Camrikron
10 Replies

3. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

4. Shell Programming and Scripting

Help with Bash piped while-read and a read user input at the same time

Hi I am new to writing script and want to use a Bash Piped while-read and read from user input. if something happens on server.log then do while loop or if something happend on user input then do while loop. Pseudocode something like: tail -n 3 -f server.log | while read serverline || read... (8 Replies)
Discussion started by: MyMorris
8 Replies

5. Shell Programming and Scripting

Append ouput in a single line

Hi Guys, I need to append some data to a new file, but i need to make sure that when i use to >> command again.I dont go to the new line. i append the data on the same line. Please help regarding the same. Thanks in advance..!!! (3 Replies)
Discussion started by: jaituteja
3 Replies

6. Shell Programming and Scripting

Input two variable on single line

Can we input two variable on single line that separate by space example user input "list jpg" it will list all jpg files in current directory (3 Replies)
Discussion started by: guidely
3 Replies

7. Shell Programming and Scripting

Two Input Lines Into Single Output Line (CSV)

Hi all, My search karate must be weak because I'm about certain something very like this has been asked and answered here many times. I'll give you the exact scenario I've wasted a few hours of my Saturday on: :wall: I'm trying to read through a very large number (~200) of router and... (28 Replies)
Discussion started by: svermill
28 Replies

8. Shell Programming and Scripting

read single chars

This reads single keystrokes and produces an output: #! /bin/bash while : ; do read -s -n 1 >/dev/null 2>&1 echo ${REPLY} done | awk '{print}' This second one don't. Even though these examples make no sense; the real code is more complicated. Who knows what the problem is... (2 Replies)
Discussion started by: elbrand
2 Replies

9. Shell Programming and Scripting

Consecutive spaces within input being converted to single space

I'm reading from a file that is semi-colon delimited. One of the fields contains 2 spaces separating the first and last name (4th field in - "JOHN<space><space> DOE"): e.g. TORONTO;ONTARIO;1 YONGE STREET;JOHN DOE;CANADA When I read this record and either echo/print to screen or write to... (4 Replies)
Discussion started by: NinersFan
4 Replies

10. Shell Programming and Scripting

single input shell script?

hey, i'm trying to write a shell script which accepts: operand operator operand then, the script would see which operator it is (using case) and calculate it... but i dont know how to do it correctly with $1 $2 $3... (eliminating accepting separate inputs) (1 Reply)
Discussion started by: quipy
1 Replies
Login or Register to Ask a Question