LinuxQuestions.org
Review your favorite Linux distribution.
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 07-27-2014, 09:28 PM   #16
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660

grail, your sample data in post #1 had create starting in position 1 of line 1. Is this always true?

Daniel B. Martin

Last edited by danielbmartin; 07-27-2014 at 09:29 PM. Reason: Clarification
 
Old 07-28-2014, 08:39 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Original Poster
Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
It was in the example, but no it does not have to be on the first line. It is assumed to always be at the start of the line (there may be white space but it is unlikely)
 
Old 07-29-2014, 08:21 AM   #18
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
In post #14 grail suggested elimination of unnecessary "g" modifiers in my "no branching" solution. That changes the code to this ...
Code:
 sed 's/^create/~create/' $InFile  \
|paste -sd" "                      \
|cut -d~ -f2-                      \
|tr "~" "\n"                       \
|sed 's/\(\b[a|i]s\b\).*/\1/'      \
>$OutFile
As a refinement I changed tr to sed ...
Code:
 sed 's/^create/~create/' $InFile  \
|paste -sd" "                      \
|cut -d~ -f2-                      \
|sed 's/~/\n/g'                    \
|sed 's/\(\b[a|i]s\b\).*/\1/'      \
>$OutFile
... and the code still works.

Then I combined two seds this way ...
Code:
 sed 's/^create/~create/' $InFile  \
|paste -sd" "                      \
|cut -d~ -f2-                      \
|sed 's/~/\n/g; s/\(\b[a|i]s\b\).*/\1/'  \
>$OutFile
... and the code generates an incorrect output file.

Please explain what went wrong with this combination.

Daniel B. Martin
 
Old 07-29-2014, 09:53 AM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Original Poster
Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Have a look at your output that comes from the cut command. Then remember that your new solution is acting on that single line for both sed commands, whereas your original solution has your last sed
working on the individual lines returned from prior sed.

Hope that helps
 
Old 07-29-2014, 10:21 AM   #20
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,879

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by grail View Post
... remember that your new solution is acting on that single line for both sed commands, whereas your original solution has your last sed working on the individual lines returned from prior sed.

Hope that helps
Yes, that helps. I need a better understanding of how sed handles combined commands. Please, if you can, point to a suitable on-line tutorial. Is it somewhere in Grymoire? Thanks!

Daniel B. Martin
 
Old 07-30-2014, 03:26 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Original Poster
Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
This is the resource I use : http://www.grymoire.com/Unix/Sed.html
 
1 members found this post helpful.
  


Reply


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
git branching on 1 person project - advantages? DJOtaku Programming 4 02-08-2012 12:11 AM
CVS branching patricius1 Linux - Software 1 02-06-2010 08:33 PM
cvs branching rtaft Linux - Software 0 06-12-2009 01:11 PM
question on shell scripting and multi-directional conditional branching jonhanna Linux - Newbie 11 01-09-2009 10:58 AM
experienced xp user branching out the.world.at.my.feet Linux - Newbie 2 11-27-2006 09:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:58 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