something odd with my awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting something odd with my awk script
# 1  
Old 01-19-2011
something odd with my awk script

The code I am using
Code:
#!/bin/sh

for FILE in *.cfg; do
awk '{
  print;
if ($1 == "host_name") store_name = $2;


if ($1 == "register") { printf("\t\t parents\t\t\t %s-ilo\n", store_name); }

}' "$FILE" > ../new-files/hosts/$FILE

sed -i -e "s/notification_options.*/notification_options \t\t d,u/g" ../new-files/hosts/$FILE


done

Most of the output files are correct with the "parents" line like this
Code:
parents             yuma-065wm-ilo

But some are ending up like this
Code:
-ilo         parents             airacademy-834

anyone know why this is happening and how to solve it?


Sample of the files I am running against

Code:
define host {
          host_name               yuma-065wm
          alias                    yuma-065wm
          address               xxx.xxx.xxx.xxx
          check_command                check-host-alive
          max_check_attempts           5
          check_interval           5
          active_checks_enabled           1
          passive_checks_enabled      1
          check_period                24x7
          obsess_over_host           1
          check_freshness           1
          event_handler_enabled           1
          process_perf_data           1
          retain_status_information      1
          retain_nonstatus_information      1
          contact_groups           admins-Email
          notification_interval           120
          notification_period           24x7
          notification_options          d,r,u
          notifications_enabled           1
          register                1
}

Thanks

---------- Post updated at 01:06 PM ---------- Previous update was at 12:54 PM ----------

^M that was the issue... dos end-of-file characters

so I ran this

Code:
for f
 do
 mv $f ${f}~ && tr -d "\r" <${f}~ >$f
 rm ${f}~
 done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

awk print odd values

value=$(some command) for all in `echo $value` do awk checks each value (all) to see if it is a odd number. if so, prints the value done sounds easy enough but i've been unable to find anything on google. (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

Odd behaviour with Expect password update script

Hi there. I've been forced by circumstance to write an expect script to handle password updates on a number of servers. There's a mix of Solaris 8, 9, 10, RedHat and Ubuntu. There's no chance the client will allow us to hook them up to a directory, so we have to make do. This script is mostly... (0 Replies)
Discussion started by: whetu
0 Replies

4. What is on Your Mind?

Odd(?) shell script practise

Hello, I often stumble over a common shell coding practise. Example 1: #!/bin/sh # # Licensed Materials - Property of IBM # Rational ClearCase # (C) Copyright IBM Corp. 1999, 2010. All Rights Reserved # US Government Users Restricted Rights - # Use, duplication or disclosure restricted... (4 Replies)
Discussion started by: MadeInGermany
4 Replies

5. Shell Programming and Scripting

Odd results when my script runs from cron..

Hi folks, So I wrote a script to run "top", "awk" out values fro the "top" and send the results to a data file. I then set it to run in cron every 15 minutes. Now I'm noticing that the script, and it's sub-commands are not always cleanly finishing and, in my investigations, I am also... (11 Replies)
Discussion started by: Marc G
11 Replies

6. Shell Programming and Scripting

Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Discussion started by: leepet01
5 Replies

7. Shell Programming and Scripting

"Odd" behavior exiting shell script

Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option? For example, if I have the example script (we'll name it ex.sh): #!/bin/sh if then echo "Bye." exit 2 fi And I execute it like this: >./ex.sh It... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

8. UNIX for Dummies Questions & Answers

Odd .sh behavior in script

Hello, I have been working on a what I thought was a fairly simple script for installing a software kit on Linux and Unix I am not new to scripting but am far from being fluent in sh scripting. any assistance would be appreciated. I have an odd bug occuring when executing the script. When... (2 Replies)
Discussion started by: robertmcol
2 Replies

9. UNIX for Dummies Questions & Answers

even odd script

I need a unix script that check for even or odd. EXAMPLE:::: please enter the number to check: 12 the output: This is an even number it has to have prompts. (2 Replies)
Discussion started by: snyper2k2
2 Replies
Login or Register to Ask a Question