LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 10-21-2013, 06:24 AM   #1
masavini
Member
 
Registered: Jun 2008
Posts: 285

Rep: Reputation: 6
stupid question about splitting command on more lines and comment them...


hi,
when i split a sed command on more lines, i'm not able to add comment to each line:
Code:
echo "bubu" | \
	# new line after a pipe is not a problem
	sed -e 's/b/c/' \
		# new line with no pipe does not work...
		-e 's/b/c/'
can someone tell me if it's possible to add comment lines between a "non piped" splitted command?

i know that the backslashes escape the return char, so the multiline command will be read as a one-liner... so it should not be possible...

if it's a stupid question (and i'm really afraid so), just sorry...
 
Old 10-21-2013, 06:59 AM   #2
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Code:
echo "bubu" |
  sed '# comment
       s/b/c/
       # comment
       s/u/a/'
 
Old 10-21-2013, 07:01 AM   #3
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
You can abuse the "back tick" command substitution, but this solution is probably more ugly and confusing than the original problem:

Code:
sed -e 's/1/a/' \
    -e 's/2/b/' `# this comment is hiding inside a command substitution` \
    -e 's/3/c/'
 
Old 10-21-2013, 07:24 AM   #4
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6
this is not that bad:
Code:
echo "bubu" | \
	sed -e 's/b/a/' \
		`# this comment is hiding inside a command substitution` \
	    -e 's/a/b/' \
	    -e 's/u/c/'
thanks!
 
Old 10-21-2013, 07:26 AM   #5
masavini
Member
 
Registered: Jun 2008
Posts: 285

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by kabamaru View Post
Code:
echo "bubu" |
  sed '# comment
       s/b/c/
       # comment
       s/u/a/'
this is nice, but it becomes tricky if sed commands contain more '...
 
Old 10-21-2013, 07:56 AM   #6
kabamaru
Member
 
Registered: Dec 2011
Location: Greece
Distribution: Slackware
Posts: 276

Rep: Reputation: 134Reputation: 134
Quote:
Originally Posted by masavini View Post
this is nice, but it becomes tricky if sed commands contain more '...
What you say also applies to sed -e '...'. If you have single quotes inside the sed command you can:

a) use double-quotes to enclose the sed command:
Code:
echo "'" | sed -e "s/'/single-quote/"
b) if your sed commands are complex (multiple commands, special characters etc.), it's more elegant to just put all these to a sed script, where you don't worry about quotes, comments etc. and just call your script with:
Code:
echo "bubu" | sed -f sedscr
 
  


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
command to comment all three lines of hdparm.conf kushalkoolwal Programming 6 03-16-2009 12:48 PM
simple stupid question about the dd command tommytomthms5 Linux - Newbie 4 09-15-2007 11:13 AM
Splitting horizontal to verical...lines venki Linux - General 7 07-04-2007 10:24 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
Splitting Text lines? 0aniel Programming 9 11-30-2005 03:08 AM

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

All times are GMT -5. The time now is 10:42 PM.

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