General :: Bash Scripts - Comparing Multiple Items Or Conditions Using 'if' Statements?
Mar 12, 2011
comparing multiple items or conditions using 'if' statements? I want to do something if one or more conditions is true, for example:
If a = 1 or b = 1.
I've tried:
[Code]...
View 5 Replies
ADVERTISEMENT
Sep 4, 2010
while learning to write bash scripts, i decided to write some script that, given an integer as input, will tell you the square root of that integer (provided the integer in question is a perfect square). i have already done on using primarily if statements and a while loop. i decided that using a case statement would be a lot simpler and i would be able to make the script more functional. here is what i have so far
[Code]....
i have tried all posible combos of using -ge or >= but i get pretty much the same thing.
the idea is, for now, if the input is greater than or equal to 0 that it will echo test. can you do this sort of thing with case statements? or will it only work if i give it specific values like [1-9] (if this is the case then i dont think the case statement will work for what i want to do)
View 4 Replies
View Related
Mar 20, 2010
I am fairly new to Linux and was needing some help on a comparing more than 2 files. I am try to come up with something that would compare at least 10+ different files to a master file and give me an output of what is missing.
Example would be: a.txt, b.txt, c.txt, d.txt compare each of them to the master.txt file, than output the missing text for each file into new file.
I came across comm and diff commands, am I looking in the right place or is there a much easier way of doing this?
View 2 Replies
View Related
Jun 2, 2010
Is there a way to compare an array in a while conditions?
I have one array that contains the results of some search and if the script has found all the items, then it should stop, so my idea is to have a while loop � la:
Code:
View 4 Replies
View Related
Sep 2, 2010
I want to compare two files and display values unique to file1. I tried using comm but it did not give me useful outputs.
comm -2 -3 file1 file2 does not work
Similar threads provide matched content. What I am looking for is unique content.
View 9 Replies
View Related
Jun 13, 2010
I've got an interesting challenge for the shell scripting wizards here. I've got a mySQL dump of three files for my amarok database with the intention of copying some files to my media server (cover art) so that I can keep the server the server and not rely on my local machine.
Step 1: Identify any cover art files on my local machine.
I did this with:
Code:
mysql -u amarok -p amarok -e "SELECT * FROM images WHERE path like '%.kde%'" > cover_art.txt
Output looks like this:
[Code]....
What I have here now is the ENTIRE album list in my collection -- and something to compare the IDs in Step 1 against. I'm going to stop here and will update the thread as I get past this stumbling block. "ID" in cover_art.txt = "image" in albums.txt... straightforward enough, right?
So the question is this: how do I create a simple shell script that will loop through the IDs in cover_art.txt (i.e. characters 0 -> 4 -- it will always be a 4 digit ID) and then search for that ID in the Albums.txt file.
View 3 Replies
View Related
Apr 13, 2011
I have 2 very long files which are quite similar:
file1.csv:
Code:
file2.csv:
Code:
I need this output:
Code:
explanation:
If the fields 3 (serie) and 4 (modello) are identical, the lines of the 2 files should be "added":
Code:
If the fields 3 (serie) and 4 (modello) are different, just print the line of both files:
Code:
Is there a way to do this without reading the (huge) files with a "while read line" loop?
View 14 Replies
View Related
Dec 14, 2010
When I select the "Open with...Other Application" context menu item I get a dialog box with multiple copies of the available programs. All of the offending program entries are Wine programs.How do I remove the extra programs from this list.this is a small problem but kind of annoying..
View 2 Replies
View Related
Jun 9, 2009
I have been messing with diff and grep for 2 days now without result
I am trying to match a file consisting of words to many separate other wordfiles in a specific directory. one by one.
What i want the script to do is to report how many matching words my main file has with every file in the directory, each in turn
setup:
Each of em are plain text files with 1 word per line
Output should be something like:
SCRIPT REPORT:
View 8 Replies
View Related
May 21, 2010
I have made some modifications to the init script that runs when my PC boots to take me to a /bin/sh shell so I can run some custom scripts. When I exit from here the init statement should mount the root file system and switch_root to it. This all works correctly however the same init statement will be run on two types of pc's and the address of the root fs is different between them. On one PC it sits on /dev/sda1 and on the other /dev/hda1. To select the appropriate addresses I used dmesg to find out if it was the i5 PC and if/else statements to select the right hard drive location.
When I try use a if/else statement in the init script it ends up preforming both the if and the else code. Is there any reason the if else statements wouldn't work the exact same in the init script (it's all shell scripts isn't it?
[Code]...
View 3 Replies
View Related
Oct 7, 2009
I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a jist of what I'm attempting, below.
1. Copy file to be processed (one file at a time, from a list of 10 files in the folder ).
Code:
for i in *
do
cp $i /home/temp
2 . Create a snapshot(n) table : Initialize n = 1
Code:
create table test insert account_no, balance from records_all; -- creates my snapshot table and inserts records in SQL
3. Checking if the table has been created successfully:
Code:
select count(*) from snapshot1 -- query out the number of records in the table -- always fixed, say at 400000
Code:
if( select count(*) from snapshot(n) = 400000 )
echo " table creation successful.. proceed to the next step "
else
echo " problem creating table, exiting the script .. "
4. If table creation is successful,
Code:
echo " select max(value) from results_all " -- printing the max value to console
[code]....
View 7 Replies
View Related
Mar 20, 2011
When I wanna use wget to download some file by http, which conditions fulfilled on the server would make that successful. I mean that such service httpd is running and so on.
View 1 Replies
View Related
Jul 25, 2011
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
View 5 Replies
View Related
Jan 8, 2010
Request your help in writing a shell script for the following requirement:
1) scan each incoming mail with conditions on sender name and subject
2) scan the mail body for set of characters and email them.
general usage is as follows: I get a mail as follows from: [URL]... subject : Urgent, reply body : name : xyz contact : 12345 the script should mail the following as subject line: n:xyz c:12345 I know procmail is a good option for this, but I'm compelled to use shell script
View 3 Replies
View Related
Apr 11, 2011
I have 5 FTP users that upload files (and subdirectories) in their home directory, i need to mirror theese directories beetween them and with a "master" directory (accessible from a 6th user). Files can contain spaces or others special caracters. All the files are in the same filesystem, and i want to use hard link because i don't want to waste 5 time the space of a single file. I tried with find but i cannot handle spaces in it.
View 1 Replies
View Related
May 5, 2011
Despite the history file is unique (~/.bash_history) I see that the multiple bash processes run on different windows are not all updating that file. I presume that the bash is not taking into account this possibility (multiple bashes on multiple windows) and writes thus the history file in a simple straightforward way. This would mean that a number of history entries are lost. I've tried to find information but had no luck so far.
View 1 Replies
View Related
Feb 21, 2010
I'm working on setting multiple switches in grep.
Here's an example of how to run my script:
would (should) produce the results of this:
Right now i have some code to catch the inputs, using a variable "z":
Code:
Then:
Code:
I'm almost positive that the problem is in the bolded line above (for one thing, it always leaves off the initial "-e"). So basically i want a string that gives me "-e input" and concatenates as many times as necessary.
View 5 Replies
View Related
Jul 11, 2011
I've written a script (that doesn't work) that looks something like this:
#!/bin/sh
screen -dmS "somename" somecommand
for i in {0..5}; do
screen -dmS "name$i" anothercommand $i
done
For some reason, if I copy and paste this into a terminal, it creates 7 detached screen sessions as I expect. If I run it from within a script, however, I get only the first session, "somename," when I run screen -ls.
Edit: If the same can be accomplished another way (e.g. with multiple screen windows instead of sessions), I would be open those solutions as well.
View 3 Replies
View Related
Jul 27, 2011
I've searched everywhere and I can't come up with a good solution. For each line I need to find the average, min, and max. I've seen plenty of solutions where the number of columns is fixed, unfortunately for me these lines can get pretty large. My thought was to read each line individually into an array, loop through the array and find the avg, min, and max that way but i haven't had much luck. I can read each line using a while loop but I'm having trouble with the array part, or perhaps that's not the best solution?
View 14 Replies
View Related
May 26, 2010
First post from a very new Linux user....I am trying to create a BASH script that will allow user to provide multiple directory names, Checks if the directory exists and if not create the directory.
I am using the following code:
Which works fine as long as the user enters a single directory name. How can I modify this so it will process all directory names user enters on the read response?
View 5 Replies
View Related
Apr 6, 2011
Fedora 15 Alpha
3861 user 20 0 904m 128m 33m S 0.7 6.4 1:11.52 xulrunner-bin
1323 user 20 0 1555m 95m 31m S 13.5 4.8 4:06.87 gnome-shell
3494 user 20 0 1028m 50m 21m S 12.8 2.5 1:43.32 evolution
I just wondering what is the difference between RES, SHR, and VIRT.
1) The VIRT always seems to be higher. Is this using the paging file system. (virtual memory on the harddisk, the swap memory)
2) Is the RES memory the actual physical RAM memory?
3) Is shared memory sharing memory with other processes?
4) Just a final question. As I am running on a HP Mini 210, memory and CPU is a resource I don't have a abundence of. So if was to compare for example 2 difference browsers i.e. firefox and midora. What should I brench mark between to 2 to find what one uses less resources?
View 2 Replies
View Related
Feb 26, 2011
I have a "Storage" partition in my hard drive which I have labeled as such and added to fstab. This is my fstab file:
[Code]...
The problem is that when I open up nautilus and click the Computer icon in the toolbar (which gives the fake computer:/// address) I see two items referring to my Storage partition:
* Storage (which appears to be of "unknown type" in the properties).
* 500 GB Hard Disk: Storage (which is the one that works).
View 6 Replies
View Related
Jul 12, 2011
I have a file1:
Code:
$ cat PF(1).out
Tmp39 PF10271.3 423 ENSP00000326063 488 1.2e-201 41-478
Tmp39 PF10271.3 423 ENSP00000338165 492 1.9e-200 46-479
[code].....
View 14 Replies
View Related
Nov 5, 2010
Is there a way, besides writing a PERL program, to read each line one by one in file A and tell if this line also exists in file B? Can this be done via a shell script?
View 6 Replies
View Related
Jul 26, 2011
I'm trying to write a script that takes two arguments, the first argument is a number, and the second argument is a filename. The shell script should indicate if the file's size is BIGGER or SMALLER the number provided. this is what i have sofar, am i on the write track, i'm hoping its just a problem with my if command
if [ $1 -h $2 ]
then
echo "$1 is bigger than $2"
else
[code]....
View 2 Replies
View Related
Sep 18, 2010
I wish to compare all the files in a directory....comparing is by content. And same files should be printed...
echo "program : $0"
cd $1
for a in *
do
[code]....
This logic did not give the correct result...
View 5 Replies
View Related
Jul 26, 2010
Iam having the following two linux files.
[Code]...
Now i want the following out puts
1. similar nos in both the file 1 and file 2 > output= File 3;
2. In file 1, but not in file 2 > out put= file 4;
3. In file 2, but not in file 1 > output = file 5;
The command sdiff is giving output with symbols > < | etc, and the such output file is not clear and ready to print. I want to print directly the output files. AND ALSO TELL ME WHERE I HAVE TO WRITE AWK PROGRAMS AND HOW TO RUN IT.
View 5 Replies
View Related
Jul 4, 2010
I have recently backed up all my documents photos etc to an external hard drive. What is the best way to check that everything has copied? I have tried diff but it was not very clear.
View 7 Replies
View Related
Nov 19, 2010
what new features in RHEL6 comparing to its older versions??
View 4 Replies
View Related
Nov 8, 2009
Two files contain:
file1:
cat
dog
fish
hamster
file2:
cat
fish
ferret
dog
How do you change the case of the letters in file1.txt to uppercase and compare with file2 all in one command?
View 2 Replies
View Related