Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-20-2011, 06:02 AM   #16
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 8,302

Rep: Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248Reputation: 2248

Well in answer to your question why the awk script failed, this is because of a simple typo:
awk '{current = $NF;getline; if($NF == current)print "match";else print "mismatch"}' file
However, it would not have worked anyway as your input shown in the last post has no white space and is delimited by a dash (-)
So based on that, the following would be the small change required:
awk -F"-" '{current = $NF;getline; if($NF == current)print "match";else print "mismatch"}' file
I would mention, and of course it is your prerogative, but it is unusual to write a (ba)sh script that then calls a ksh script, especially when you try to include
it within a function:

I am not even aware that this would work as my understanding is the interpreter needs to be the first line (I could be wrong).

Is there a reason for the mash up? On a quick scan there does not appear to be anything particularly ksh specific that required this?

Anyhoo, let me know how you get on.
Old 08-28-2012, 05:36 AM   #17
Registered: Aug 2011
Distribution: Linux Mint
Posts: 103

Rep: Reputation: Disabled
Suppose you had a large file including thousands of lines and you may have a few lines that are different with consecutive lines, you may want to simply print its line number with the code:

awk '{current = $NF; getline; if($NF != current) print NR}'
If you want to check the number of fields rather than the content, you can try the similar code:

awk '{current = NF; getline; if(NF != current) print NR}'
Hope this additional solution can help those who has questions that are relevant but not exactly same.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to convert values on successive lines into consecutive ranges? kmkocot Programming 5 07-09-2010 11:59 AM
sed/awk: Three consecutive blank lines in a file, how to delete two of them? recomboDNA Programming 8 06-17-2010 10:50 AM
Shell script to read lines in a text file and filter user data srimal Linux - Newbie 5 10-21-2009 08:41 AM
need help with awk-script (compare two lines) Mauline Programming 2 11-27-2008 05:12 AM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 06:39 AM

All times are GMT -5. The time now is 11:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration