LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-20-2011, 05:02 AM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,009

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193

Well in answer to your question why the awk script failed, this is because of a simple typo:
Code:
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:
Code:
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:
Code:
DBcounttry_finalfunction()
{

#!/bin/ksh
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
cristalp
Member
 
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:

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:

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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:56 AM.

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