My first script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My first script
# 1  
Old 08-20-2012
My first script

I'm trying to get this script to work i'm close but there's some wrong any help is welcome. I have a bunch of text files in a directory which are a list of numbers i'm trying to get this script to look for a random number in the list and tell me in which text file that number is.

---------- Post updated at 04:16 PM ---------- Previous update was at 04:15 PM ----------

#looking for a ticket clear echo "Ticket #:" read ticket echo "number entered" "$ticket" echo grep -l "$ticket" /home/ubu/Desktop/jobs/*.txt
# 2  
Old 08-20-2012
Is this homework?

I don't think pasting your code worked. Try pasting it again in code tags

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.
# 3  
Old 08-20-2012
When posting code use [code] and [/code] tags around your code eg:

Code:
#looking for a ticket clear
echo "Ticket #:"
read ticket
echo "number entered" "$ticket"
echo
grep -l "$ticket" /home/ubu/Desktop/jobs/*.txt

What is the problem? This appears like it should do what you describe.
# 4  
Old 08-20-2012
Nope i'm justrying to learn some sripting and this the first one i can use myself this is the code : #looking for a ticket clear echo "Ticket #:" read ticket echo "number entered" "$ticket" echo grep -l "$ticket" /home/ubu/Desktop/jobs/*.txt
# 5  
Old 08-20-2012
Soething has gone wrong with your post. The code posted appears to contain html characters and some extra punctuation.

Did you mean:

Code:
#looking for a ticket
clear
echo "Ticket #: "
read ticket
echo "number entered: $ticket"
grep -l "$ticket" /home/ubu/Desktop/jobs/*.txt

Ps. In removing various &quot and semi-colons and also inserting missing line-breaks, I may have fixed the syntax problems by accident.

@Chubler-XL. Posts crossed. Great minds think alike. Comparing our scripts, you lost a "clear" and I lost an "echo" !

@shadow.wodahs . Line breaks, character spacing and character sets are critical to successful scripting. A semi-colon can be used as a substitute for a line break, but it often makes scripts unreadable.

Last edited by methyl; 08-20-2012 at 06:39 PM.. Reason: xrefed wrong poster!
# 6  
Old 08-20-2012
yes i did. Well it gives me the list of all text files in the folder but i just need the one name of the text file where ticket number i'm looking for is. so say i type 7932 and this number is in file.txt but insted of just getting that i get the list of all text files file.txt,file2.txt,file3.txt etc..
# 7  
Old 08-20-2012
I doubt that grep is lying to you, maybe the ticket number -- or numbers containing that ticket number -- do exist in all those files.

Show some sample data from those files so we can help narrow it down.
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question