Help answer threads with 0 replies.
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, 05:02 AM   #16
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191

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, 04: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 10:59 AM
sed/awk: Three consecutive blank lines in a file, how to delete two of them? recomboDNA Programming 8 06-17-2010 09:50 AM
Shell script to read lines in a text file and filter user data srimal Linux - Newbie 5 10-21-2009 07:41 AM
need help with awk-script (compare two lines) Mauline Programming 2 11-27-2008 04:12 AM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:50 PM.

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
Open Source Consulting | Domain Registration