Sponsored Content
Top Forums Shell Programming and Scripting Nested if statements with word/number extracts Post 302901402 by demmel on Tuesday 13th of May 2014 04:01:02 PM
Old 05-13-2014
Quote:
Originally Posted by gandolf989
Here are the files that you need. My name is Brian.
You should know that so you can add my name to
your assignment when you turn it in.

Smilie


Code:
$ cat ./bingo.sh
#!/bin/bash

if [ $# -lt 2 ]
then
echo ""
echo " ERROR : Invalid number of arguments"
echo " Usage : base_file, dump_file"
exit 1
fi

export BASE_FILE=$1
export DUMP_FILE=$2
export BASE_NUMBER=`head -1 ${BASE_FILE}`

if [ `grep -c BINGO ${DUMP_FILE}` -gt 0 ]
then
   export TARGET_NUMBER=`grep BINGO ${DUMP_FILE} | cut -d" " -f2`
   if [ "${TARGET_NUMBER}" -gt "${BASE_NUMBER}" ]
   then
      echo "Your BINGO number is bigger!"
   else
      echo "Your number is not bigger!"
   fi
fi

# rm -v ${DUMP_FILE}

$ cat base.txt
5
$ cat dump.txt
INGO 001
INGO 001
INGO 001
INGO 001
BINGO 999
INGO 001
INGO 001
INGO 001
INGO 001
INGO 001


Thanks Brian from Pittsburgh AKA gandolf989.

This is actually part of a solution for daily manual intervention that I face. It will surely help me a great deal. I'll make sure to put your nick and domain as author as well! (nobody will start contacting you so your fine LOL)

I'm still trying to understand all the variable that you set up, however I can thank you already.


Code:
if [ $# -lt 2 ] then echo "" echo " ERROR : Invalid number of arguments" echo " Usage : base_file, dump_file" exit 1 fi

The return code mapping 2 was helpful. OK got that.

export BASE_FILE=$1 export DUMP_FILE=$2 export BASE_NUMBER=`head -1 ${BASE_FILE}`I still couldn't understand how these variables run into place.
Maybe its the parameter I run within the command?
"/path/bingo.sh base.txt dump.txt"



Code:
if [ `grep -c BINGO ${DUMP_FILE}` -gt 0 ]

Cool, got that.

Code:
export TARGET_NUMBER=`grep BINGO ${DUMP_FILE} | cut -d" " -f2`

Would the number extract parameter work only if its present in column 2, being separated by space? If not, its no big deal, I can arrange the correct column as dump file will always be with the same columns.

Code:
if [ "${TARGET_NUMBER}" -gt "${BASE_NUMBER}" ]

Great

Sounds good, I'll start some testing!

Thank you very much!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to have a Script that extracts files?

Hi, I know there is a way to have a script that include files in a way that once we run the script, it would extract those files. Kinda similar to how zip files work. For example: - I have a script called test.sh - Once I run this script, it will extract file1, file2 and file3 and then... (2 Replies)
Discussion started by: pgarousi
2 Replies

2. Shell Programming and Scripting

Nested if statements with && and ||?

Hello, I'm a shell scripting noob and new to this forum as well. My question is can nested if statements be done with && and || instead and if it can be done can someone provide an example pls. Thanks in advance for the help (1 Reply)
Discussion started by: zomgshellscript
1 Replies

3. Shell Programming and Scripting

syntax question in regards to nested awk statements

Hello all, I am writing up an input file and I was hoping I could get some guidance as to how to best consolidate these 2 awk statements for 1 while loop. Here's my input file # cat databases.lst #NOTE: These entries are delimited by tabs "\t" #oracleSID name/pass # db11 ... (2 Replies)
Discussion started by: Keepcase
2 Replies

4. Shell Programming and Scripting

Nested looping statements

I cannot get the code below to work correctly. The IF statement works just fine, but not the looping. The inner loop tries to find files for a given vendor; if found, I need to sleep giving another process time to move the files. Once the given vendor's files are gone, then I want to move on to the... (1 Reply)
Discussion started by: dgreene
1 Replies

5. UNIX for Advanced & Expert Users

Extracts files names and write those to another file in different directory

Hi , Need to shell script to extracts files names and write those to another file in different directory. input file is inputfile.txt abc|1|bcd.dat 123 david123 123 rudy2345 124 tinku5634 abc|1|def.dat 123 jevid123 123 qwer2345 124 ghjlk5634 abc|1|pqr.txt 123 vbjnnjh435 123 jggdy876... (9 Replies)
Discussion started by: dssyadav
9 Replies

6. Shell Programming and Scripting

Help with sort word followed by exponential number and numeric number at the same time

Input file: ID_34 2E-69 2324 ID_1 0E0 3254 ID_1 0E0 5434 ID_5 0E0 436 ID_1 1E-14 2524 ID_1 5E-52 46437 ID_3 65E-20 45467 ID_1 0E0 6578 ... Desired output file: ID_1 0E0 6578 ID_1 0E0 5434 ID_1 0E0 3254 ID_1 5E-52 46437 ID_1 1E-14 2524 ID_3 65E-20 45467 (5 Replies)
Discussion started by: cpp_beginner
5 Replies

7. Shell Programming and Scripting

Nested awk Statements

Hello again everyone, yes, I'm back again for more help! So I'm attempting to read two separate files and generate some XML code from that. My current code is: BEGIN { print "<?xml version=\"1.0\" encoding=\"utf-8\">" print "<Export>" } { x=1; print "<section name=\"Query" NR "\">"... (5 Replies)
Discussion started by: Parrakarry
5 Replies

8. Shell Programming and Scripting

Print only word not number

Hi, Need to extract only words not numbers #cat test.txt 123456 oracle web 56789 s21adm Required output #grep <options> test.txt oracle web s21adm Note, in between integer "s21adm" is required but not with full integer "123456" and "56789" (6 Replies)
Discussion started by: ksgnathan
6 Replies

9. Shell Programming and Scripting

GPS extracts fix delta time

Hello all, I am currently trying to find the delta time from some GPS log. I am using the following script with awk. But the script result shows some incorrect values (delta time some time = 0.2 but when I check it manually it is equal to 0.1) My final goal is to get a script that print... (7 Replies)
Discussion started by: redafenj
7 Replies

10. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies
All times are GMT -4. The time now is 08:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy