Looking at writing another awk program here to find a pattern on a text file. If patterns aren't found I want the awk program to exit and then bash to file a failure log on the local machine. Then later a management framework we have in place will read if that failure log file exists and flag the computer as being failed in our database.
I am pretty good with my bash skills but awk and sed still hang me up from time to time and I cannot wrap my head around this one so figure I'd ask the gurus here, as I am probably just being an idiot on how this works.
Here is an example:
new_pattern is determined by a variable parsing through the source file. I am still testing out various ways of doing this. Find command, data array, and also sourcing the list of proper names. The file is comma separated. I am also passing the /pattern/ part from bash as a variable. That works.
This is hanging up so I think I need to do he if statement in awk and not use bash. However, if the pattern matches the script works fine. This is great, but I need some way to track down failures down the road and manually fix them. Basically, I work for a company that has merged with other companies and having to bring everything up to the new parent company's standards (naming conventions of files, folders, etc) So I am matching patterns of what the standards should be, versus what they are currently named (supplied via master text file from remote offices) and then trying to automate the process. Tons of computers out in the wild right now. There are going to be failures because of certain unknowns.
So, I am trying some if statements in awk instead:
This seems to not be working as I intended. Sorry for the probably easy noob question but I am not wrapping my head around this. Currently reading through my awk books as well.
Wow, you're good. Yes, my script expands the variable properly with the proper quotes I just didn't copy/paste the right from my script.
Also, running grep beforehand to make sure those are in the master list is actually an easier approach, and I knew that but didn't think of it. Again, good thinking.
I am thinking of this:
Unless there is a good reason I should not check the exit status of grep?
This at least gives me something to work with. Thanks again mate!
Hi all
OS - RHEL6.4
I have input file -f1.txt
I need to search line which starts with \Start and read next line till it gets blank line and join them all. I need to trim any trailing spaces for each line.So output.txt should be..
\Start\now\fine stepwatch this space for toolsends... (7 Replies)
I had a spot of trouble coming up with a title, hopefully you'll understand once you read my problem... :)
I have the output of an ldapsearch that looks like this:
dn: cn=sam,ou=company,o=com
uidNumber: 7174
gidNumber: 49563
homeDirectory: /home/sam
loginshell: /bin/bash
uid: sam... (2 Replies)
Is there a way with aw to print all lines after a string is found
There is a file like this
.......
........
2012/19/11 :11.58 PM some data
lne no date
2012/19/11 :11.59 PM some other data
2012/20/11 :12.00 AM some other data
some line without dates
some more lines without dates... (8 Replies)
I have a shell script (#!/bin/sh) that interacts with Appworx and Banner Admin. In my script I want to check the exit status of awrun before continuing. awrun can run for 10 seconds or it can run for over a minute. So my question is, will it go through my if statement before awrun may even be... (2 Replies)
I am trying to do some thing like this ..
In a file , if pattern found insert new pattern at the begining of the line containing the pattern.
example:
in a file I have this.
gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin
if i find feedthru_pin want to insert !! at the... (7 Replies)
I'm preparing for exam and one of exams is to write own test command...
I wonder if in unix is a command which just returns exit code you specify..
I know I can easily write a function like this:
exStatus() {
return $1
}
-> my question is rather theoretical
thank you! (9 Replies)
Hi All,
My file :
$ cat my.txt
AA:22:note:AA
BB:AA:help:XX
CC:14:AA:CC
ZZ:AA:hello:AA
A) <searching "AA" as 2nd field in all lines of my.txt >
$ awk -F ":" '{ if ($2 ~ /AA/) print "found in line - " NR; else print "Not found"}' my.txt
Not found
found in line - 2
Not found
found... (7 Replies)
Hi,
I have a main program which have below lines
-
awk -f test.awk inputFileName
-
I wonder how to check status return from awk script.
content of awk script:
test.awk
---
if ( pass validation )
{
exit 1
}
else
{ (1 Reply)
i downloaded a text file from metalab.unc.edu called sh.txt and in this reference manual it refers to shell scripting exit status .. at the end of one of the examples that author gave an exit status of 127..
to what does a 127 exit status refer too and what is its purpose in the code.
moxxx68 (1 Reply)