Trying to make a bash script that goes through directory files and changes things


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to make a bash script that goes through directory files and changes things
# 1  
Old 04-01-2017
Trying to make a bash script that goes through directory files and changes things

I'm trying to write a script in a directory that goes through the column the user specifies of 4 files that are inside the directory and calculates the min and the max values. This means that if the user specifies column 5, the script will go through column 5 of all 4 files and all that should give only one min and one max. Then the script would subtract the min from the max and then divide that value by two (finding the average). It would then replace values in that same column the user inputed earlier for all 4 files that are less than the average AND greater than the min with ‘ttt’ and ones that are greater than or equal to the average AND less than the max with ‘gcc’.

So far I've set up my script so that it checks the user input with this (giving the user an error if the number put is greater than 10)-

Code:
echo "Please enter a column you wish to change: "
read userinput
if [ ${userinput} -gt 10 ]; then
        echo "Error"
else

how do I continue with the rest of the script with searching the columns for min and max, and replacing the content of the files?

Last edited by Scrutinizer; 04-01-2017 at 06:16 PM.. Reason: ICODE tags -> CODE tags
# 2  
Old 04-02-2017
Please become accustomed to provide decent context info of your problem, like OS, shell, related environment, preferred tools, representative input sample, desired output, and the logics connecting the two.

Is this a homework / classroom problem? Homework and coursework questions can only be posted in this forum under special homework rules.

If this is NOT homework, please show us the background of the problem, e.g. the company branch / project you work for, or the type of research.

Thank You.

The UNIX and Linux Forums.
# 3  
Old 04-02-2017
Ah okay, this is a homework assignment yes. My apologies. I'll delete this thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script make itself executable

Is there a way to make this make itself executable? Thanks. :-) cat > somescript.sh << \EOF #!/bin/bash block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Block count:/ {print $NF}') reserved_block_count=$(sudo tune2fs -l /dev/sda1 | awk '/^Reserved block count:/ {print $NF}') perl -e... (4 Replies)
Discussion started by: drew77
4 Replies

2. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

3. Shell Programming and Scripting

Bash script to copy apache log files to client directory

Our Apache log files are written to a location on the server that we as clients have no access. Don't ask. Every month, I have to e-mail the administrator to have him manually copy our Apache log files to a directory in our file space. You can probably guess how efficient it is to do things this... (3 Replies)
Discussion started by: gregraven
3 Replies

4. UNIX for Dummies Questions & Answers

Remove all things from directory

Which command will be good to use when I want to remove all files and directories from the directory (i want to have empty derictory). Sorry for my English :p ... (3 Replies)
Discussion started by: WrzaSQN
3 Replies

5. UNIX for Dummies Questions & Answers

Make directory in script

I'm creating a file that reads: cd $HOME echo What would you like to call the tar file? read TARNAME tar -cf $TARNAME.tar labs/* mkdir backups mv $TARNAME.tar backups/ Now my problem I'm having is that some people have the backups directory and some don't. How can I make it that if they... (1 Reply)
Discussion started by: bbowers
1 Replies

6. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

7. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

make directory script

Hi, I try to write a script to create a new directory. #!/bin/bash echo "Please enter folder name (6 characters only) :" read foldername mkdir /home/user/$foldername $foldername >> /home/list/list.txt My question/situation: 1) how to ensure the folder name MUST BE 6 characters... (0 Replies)
Discussion started by: malaysoul
0 Replies

9. Shell Programming and Scripting

How to make bash script abort?

I have a little bash script that includes make to compile with g++ and then a statement to actually run the compiled program. When it (the script) gets a syntax error, it does not abort and continues to run the previous version of the program. How can I make the script abort when g++ generates a... (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question