Help needed - Newbee here


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed - Newbee here
# 1  
Old 05-22-2013
Help needed - Newbee here

I am very new to shell scripting. please help me in this scenario.

when we run the script, It should ask user to enter the input (for example, ticket number like below)

B1234567
B2345678
C1245782
.
2. Once user enter the input or,paste the input, the script should check each and every row, the lenght of the row should not exceed 8 characters, if it exceeds, script has to throw an error like "invalid input"..

3, if each and every have less than or equal to 8 character, script has to save the input to one text file..


This is my scenario, please help me to get it done.
Thanks in advance

sorry for my bad english
# 2  
Old 05-22-2013
This is a simple shell script showing one way:
Code:
$ cat enter_ticket_number.sh
output_file="$1"
while true
  do
    # Ask the question
    read -p "Enter a ticket number: " REPLY

    # Any thing entered?
    if [ -z "$REPLY" ]; then
      echo "invalid ticket number, retry."
    fi

    # exit?
    if [ "$REPLY" = "x" ]; then
     exit
    fi

    # Check if the ticket number is valid
    if [ ${#REPLY} -gt 8 ]; then
      echo "invalid ticket number, retry."
    fi

    echo $REPLY >> $output_file
  done

Run script passing in file name to add ticket numbers to:
Code:
$ enter_ticket_number.sh /tmp/tickets.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed

First of all, let me state that I am a windows admin. I have a windows share mounted to /mnt/server I need a script that will either login as sudo or perform commands with sudo rights. I need the script to copy all of the users /home folders to the mounted windows share. Now If I can... (2 Replies)
Discussion started by: EricM
2 Replies

2. HP-UX

Simple Newbee question

Hi HP-UX users. If you can help with the following I would be grateful. I am starting off on my HP-UX learning/certification path and need to acquire an HP-UX machine. I would prefer HP hardware, ie. PA-RISC and see that there are many for sale on eBay, etc., and was hoping someone on this forum... (2 Replies)
Discussion started by: patcom
2 Replies

3. Shell Programming and Scripting

Help Needed

please reply for this https://www.unix.com/shell-programming-scripting/111493-cutting-lines.html its really urgent (1 Reply)
Discussion started by: jojo123
1 Replies

4. Shell Programming and Scripting

help needed...

Guys, There is a file where there are 1000s of records. In the file if some condition satisfies in a certain TAB record (TAB would be first 3 digits of a certain record) then move TAB and all the records (or lines) after TAB to new_file, until another TAB record is encountered in the same... (1 Reply)
Discussion started by: Prat007
1 Replies

5. Shell Programming and Scripting

Newbee lost in unix land

I am writing a shell script and I am calling wc -l. I need to assign the results of this call to a varaible and it's not working the way I think it should: xx= wc -l $1 What am I doing wrong? Thanx (1 Reply)
Discussion started by: dortoh
1 Replies

6. UNIX for Dummies Questions & Answers

little help needed..

hi everyone i'm a noob trying to learn unix language.. but seems like i got no leads on how to start.. i'm playing with the 'ps' command.. i'm trying to show the pid, ppid, username, command, cpu utilization (in desc order), process start time and process status.. all in a command.. am i able... (3 Replies)
Discussion started by: hilofat
3 Replies

7. Shell Programming and Scripting

Newbee Needs Help - Time comparison

I am very new to Unix so please bear with me! I am trying to write a script that will compare file creation time with the current time so I can be notified if a file is more than an hour old. Can anybody point me in the right direction on this??? Thank you in advance for any help!!! It is GREATLY... (4 Replies)
Discussion started by: danedder
4 Replies

8. UNIX for Dummies Questions & Answers

Unix Newbee :-)

Hi , i have jus started learning basics of unix .I have few queries : 1) what is meant by unix box server? 2) what is the difference between unix and linux (is it jus x-windows graphical system or is there anything more than that?) 3) Can i get any free download of unix so that i cud... (7 Replies)
Discussion started by: vivekshankar
7 Replies

9. UNIX for Dummies Questions & Answers

newbee - copy data from UNIX to Linux

I have to setup a new server (linux) and I have to copy the data from the old unix system to the new one. Can I access the unix data in dos? Please help. I know little about linux and unix (3 Replies)
Discussion started by: steven5046
3 Replies

10. UNIX for Dummies Questions & Answers

inetd problems?!?!?! - Help complete newbee!!!

I'm in real trouble :( One of our Ultra 10's went down and our Unix guys aren't around for another week or so (eek!) and we need to get it up and running again ASAP so after hooking up a keyboard and monitor I switched it on and it went through system check. It then started to display the... (4 Replies)
Discussion started by: d_cottam
4 Replies
Login or Register to Ask a Question