Check last line with gawk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check last line with gawk?
# 1  
Old 10-04-2006
Check last line with gawk?

I am writing a gawk script that checks some basic code conformance rules (java text files) using gawk. So far, so good.

But I have a requirement to ensure that the last line in the java source files is "/* eof */". The below snippet works BUT is called more than once per file as / / matches a "few" too many expressions. So how do I perform this check only once???
...
/ /{
if ( tail -1 FILENAME ~ "/* eof */" ) {
print "Yeah"
}
}
...

Go easy, I'm a newbie.
# 2  
Old 10-04-2006
Or can I do something like:

/\/\* eof \*\// {
if (Check if last line of file)
{
print FILENAME ": yay woot foo" > "/dev/stderr"
}
else
{
print FILENAME ": failed" > "/dev/stderr"
}
}

So how do I "Check if last line of file"?
# 3  
Old 10-04-2006
# 4  
Old 10-04-2006
Thanks for the idea,

Now how do I get it to work?

...
END{
theEOFComment = tail -1 FILENAME
print theEOFComment
if (match(theEOFComment, /eof/)) {
print "Yeah"
}

...
}
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

2. Shell Programming and Scripting

gawk to remove last character in a line or string

I am outputting a line like this print $2 "/" $4The last character though is a ":" and I want to remove it. Is there any neat way to remove it? Or am I forced to do something like this: print $2 "/" substr($4, 1, length($4) - 1)Thanks. (6 Replies)
Discussion started by: benalt
6 Replies

3. Shell Programming and Scripting

Check if line has a space

Hi, I want to check if the given line from a text file has a spaces in between. if it does, then I want to add '"' double quotes at the beginning and end of the line. Otherwise leave the line as it is. For example, below is the sample content from my file. $cat file.txt test1 test2... (6 Replies)
Discussion started by: svajhala
6 Replies

4. Shell Programming and Scripting

gawk (dos) insert backslash at end of line

I have created with the DOS-command dir a list of a directory. Directory of C:\Users\User\Documents 09.06.2011 20:50 48.322 file1.txt 02.11.2010 23:00 9.216 file2.txt 15.12.2010 21:06 26.793 file2.txt Now i would like to add the directory ahead of the filename. Therefore a... (6 Replies)
Discussion started by: sdf
6 Replies

5. Windows & DOS: Issues & Discussions

Cannot run command line scripts in perl or gawk

I originally posted this to a different forum (I am a new Perl user) and realized the error so I will ask here. I am on a WindowsXP machine trying to run perl and gawk scripts from the command line. I have perl and gawk installed and environment set to C:\perl\bin and cannot get a script to... (2 Replies)
Discussion started by: 10000springs
2 Replies

6. Shell Programming and Scripting

solved -gawk, search for pattern - mark the previous line as a variable?

Im trying to parse ifconfig with awk and setup a bunch of variables in one shot. But Im having trouble figuring out how to work with data in previous lines. ifconfig output: eth0 Link encap:Ethernet HWaddr 00:50:DA:10:7F:1B inet addr:10.10.10.10 Bcast:10.10.10.127 ... (0 Replies)
Discussion started by: trey85stang
0 Replies

7. Shell Programming and Scripting

check line by line in a file

Hi there How can I check line by line in a file? I need to compare the first value with the second to know if they are equal. If those values are equal, I require to send "TRUE" to the output or "FALSE" otherwise until the complete file has been read. Thank you (6 Replies)
Discussion started by: loperam
6 Replies

8. Shell Programming and Scripting

how to check by line

Hello, Member or professional need help how to check by line Example of the file is here cdr20080817164322811681txt = 26 char cdr20080917164322811txt = 23 char cdr20081017164322811683txt = 26 char cdr20081117164322811txt = 23 char I want it to be is this cdr20080917164322811txt is... (4 Replies)
Discussion started by: ooilinlove
4 Replies

9. Shell Programming and Scripting

check line in a file

Hi all, How do we check in a file whether a line started with KEYWORD2 is right after the line started with KEYWORD1 for example, this file content: Abcdef gsh iasdi 94945 9085095 lksdjlkj KEYWORD1 skljfi slakjfoi ' opiport sdfl KEYWORD2 ksjflsk jfasope jkdfsk393 89374982 23 ... (3 Replies)
Discussion started by: fongthai
3 Replies
Login or Register to Ask a Question