Hey guys, I'm currently working on a project for comp sci course, and I'm very green to Unix and scripting, and only have a semesters worth of programming knowledge (bare with me! sorry!). What I'm trying to do is make a 'if ... then ... fi' control structure that takes user input and then searches the file where data is going and if the name already exists in first field it prints error msg (cant have two of same name in data file)
So basically its sort a mock inventory auto parts management script, user goes to add new parts, first is prompted to enter name of part ... I then want to compare user input to first field of all entires already in my data file (auto.parts) ... if the part exists print error message, if not continue and add part to data file.
So far I got:
It seems to not be comparing the user input to first field (first field is where auto part name goes i.e <partname>:<stuff>:<stuff>:<etc..>), it just ignores the statement and continues on ... allowing me to enter 100 Brake:etc:etc:etc lines if I wish too, which it shouldn't!. I'm almost positive i'm using wrong syntax in my if [statement]. ANY help, or finger pointing me to a great website for beginners would be MUCH appreciated!!
Aww Ok, I know what you mean what is the proper way to add that to my if statement?
Also, I'm trying to use grep i.e:
Is this even allowed? I'm scratching my head here, but on here for hours scouring the internet looking for a solution but most places I find either do poor job explaining (to me at least) what I need to add to my structure.
grep -q "^$apname" auto.parts && echo "is in parts"
Thanks for reply, the grep code is close to working, im just getting problem now where it always says part is duplicated, but hopefully I can figure it out from here.
Quote:
Morever: if you are entering "100 Brake", you need to split the quantity from the part.
Try this
I did a poor job of explaining, I don't need to enter quantities, I was just figuratively saying my busted script was allowing more then one to be entered.
But, thanks for the help, hopefully I can get it from here now that I'm aware about specifying the file I gotta look into.
---------- Post updated at 07:56 PM ---------- Previous update was at 06:40 PM ----------
OK! I'm still messing with it and its not working, it keeps telling me everything is duplicated no matter what I type.
My code looks like:
Sorry to be a bother but this is really annoying me!
Is there a negate expression I should be using in my else statement? Something like:
If I don't need it, what is the regular expression to see if the string is NOT in a file just so I will know it for future reference? Tried searching but could not find anything.
Hi!
I am using Emacs 22.3.1 and the Control-G command will not work to cancel. I took my init.el file out of the mix and it stills does not work. I am not sure when I upgraded from 20.4 to 22.3.1, if it worked, but it certainly does not now.
Any thoughts... (6 Replies)
If I'm the admin for the financial system and I want to configure authorization pf file system permission.Also, The first rule is that Managers and clerks can read and write billings for all cases. The second rules is that Paralegals and administrative assits can read and write billings only on... (2 Replies)
hi all,
I am writing a script and beginner in shell scripting. I have tried the below script. could you please check and let me know whether the below scirpt is correct.
Unix details : HP Unix
Input file.
cat input.txt | tail -4
HTS40002.W1978.PROM
HTS40003.W1978.PROM... (17 Replies)
Preview of command prompt
f ---> to start ferret
q----> to stop ferret
asp@nex:~$ f
NOAA/PMEL TMAP
FERRET v6.82
Linux 2.6.18-308.8.2.el5PAE 32-bit - 08/03/12
3-Dec-12 16:44
yes? go my.jnl
yes?column=4/skip=1/type=num,text ............filename.txt
---... (4 Replies)
I am pretty new to linux so forgive me for asking a basic question :P
I am using SSH to control 40 machines. What i am trying to do is remotely bash a shell script on each machine. I am using a for loop to bash every script, code as follows.
code in host machine runallworkers.sh:
...
... (2 Replies)
folks;
I have a script to remove any files that older than 14 days then move any files that younger than 7 days to another directory. but for some reason it doesn't move the files, when i do it manually it works but not through the script. i tried 2 different ways in writing the move part but it... (6 Replies)
Folks;
I need some help with these:
1. understanding how to control access rights and manage visibility using FTP in Solaris, in other words, I need to use FTP in Solaris to be able to give some users access to add/modify data to/from the UNIX server.
2. How can i control the space allowed for... (2 Replies)
I'm new to shell scripting and am having a problem trying to do something in C shell. I want to write a script that will input something instead of a user doing it. For example, using the command 'write' the user is supposed to type something to be sent to another user. I want a script to be able... (3 Replies)
Hello
I am working on cleaning up permissions on Oracle mountpoints and datafiles in unix. I am looking for a script or a scripting idea to 1st.
1. grep for owner oracle
2. ensure its a directory owned for oracle
3. chmod 750 on the oracle owned directory.
4. grep for oracle files, etc... (3 Replies)
I am writing a script that will identify the oldest file in a directory. Here's the syntax:
#!/bin/ksh
cd directory
chmod 777 *
ls -r -1t > file1
sed -n -e "1P" < file1 > file2
So my problem is, now I have file2, which contains the name of the oldest file in the directory. How do I use,... (1 Reply)