LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Closed Thread
  Search this Thread
Old 11-12-2013, 02:16 PM   #1
jeffwang66
LQ Newbie
 
Registered: Jan 2011
Posts: 27

Rep: Reputation: 0
Question about writing a bash script


Hello,

I want to write a script with sed to delete all contents after '#', except if '#' appears in string "".

For example,

input file:

test #delete
"test #not delete" #delete
#delete

I want the output is:

test
"test #not delete"

Can anyone help me?

Thanks
 
Old 11-12-2013, 02:23 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,367
Blog Entries: 24

Rep: Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298Reputation: 4298
I believe that you will find that very difficult if not impossible with sed.

Sed does not support look-ahead/look-behind so it will be very difficult to handle # inside quotes - or other places where one might occur.

You might also consider that such an expression would also remove the she-bang - #!/bin/sh - if used on a shell script which seems to be what you are trying do.

Last edited by astrogeek; 11-12-2013 at 02:29 PM.
 
Old 11-12-2013, 02:35 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
why two threads?

https://www.linuxquestions.org/quest...pt-4175484348/
 
1 members found this post helpful.
Old 11-16-2013, 06:15 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,982
Blog Entries: 46

Rep: Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203Reputation: 3203
Moderator Response

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate of https://www.linuxquestions.org/quest...pt-4175484348/
 
  


Closed Thread


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing a bash script Leroy1990 Linux - Newbie 6 03-01-2012 03:40 PM
Writing a bash script s_b Linux - Newbie 7 10-08-2008 12:32 PM
Writing a bash script. lebabyg Linux - General 2 03-31-2007 11:39 AM
Bash (help writing script) lebabyg Linux - General 7 07-04-2006 05:22 PM
writing a bash script poiuytrewq Linux - Newbie 2 10-07-2004 10:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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