LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-19-2012, 10:05 PM   #31
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,084

Original Poster
Rep: Reputation: 287Reputation: 287Reputation: 287
Post


No syntax error but the output isn't right.

Using this code ...
Code:
echo "Method of LQ Guru grail,"
echo " modified to reverse order of output words."
awk -F "" '{orig = $0;
   for(i=1;i < NF-2;i++) 
   if(substr($0,i+2) ~ $i$(i+1))
   {parts = parts sprintf("%s ",$i$(i+1));
    gsub($i$(i+1),"")}print $0,parts orig}' < $Work02 > $Work14
Part of Work02 ...
Code:
aardvark
abarticulation
abatable
abbesses
abbreviature
Part of Work14 ...
Code:
advk ar aardvark
abarculaon ar ti abarticulation
atle ar ti ab abatable
abbs ar ti ab es abbesses
abbviatu ar ti ab es re abbreviature
Daniel B. Martin
 
Old 08-19-2012, 10:17 PM   #32
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
Thought you might have fixed this one up Sorry but not near a linux machine at the mo so replies are untested. Simply reset parts prior to for loop, ie parts = ""
 
1 members found this post helpful.
Old 08-20-2012, 02:16 PM   #33
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,084

Original Poster
Rep: Reputation: 287Reputation: 287Reputation: 287
Quote:
Originally Posted by grail View Post
Simply reset parts prior to for loop, ie parts = ""
Your solution now works well in all respects.

Thanks to grail and firstfire for patience and expertise. This thread is now marked SOLVED. It may be called 2xSOLVED because we have two solutions, a sed and an awk.

Daniel B. Martin
 
  


Reply

Tags
awk, grep, regex, sed


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
Getting the no repeated pairs out of a a string charlitos Programming 2 02-17-2009 02:52 AM
LXer: 25 Arguments for the Elimination of Copy Protection LXer Syndicated Linux News 0 10-20-2008 07:50 AM
Script to move directories based on first letter to a new directory of that letter tworkemon Linux - Newbie 8 01-30-2007 07:18 PM
+performance +gcc +elimination C++Boar Programming 6 09-02-2004 11:48 PM
Cups elimination beowulf405 Linux - Newbie 5 06-30-2004 09:16 PM


All times are GMT -5. The time now is 02:16 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration