Using sed for multiple matches instead matching whole fileHow do I combine all lines in a text file into a single line?'tail' command not getting only the new linesUsing Ubuntu command line to replace text in huge fileretain white spaces in fields when using awkdiffrence between two files of different row numbersModify a list: filter it, and rearrange the values in the resultError while using sed fileRemoving multiple space using sedRemove exact matching word using sedWhat's wrong with this backup script?

How to make payment on the internet without leaving a money trail?

Is there any use for defining additional entity types in a SOQL FROM clause?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Why is the design of haulage companies so “special”?

Ideas for 3rd eye abilities

Re-submission of rejected manuscript without informing co-authors

A poker game description that does not feel gimmicky

How can I add custom success page

Why Is Death Allowed In the Matrix?

Is there a familial term for apples and pears?

Is a vector space a subspace of itself?

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

Filling an area between two curves

What do the Banks children have against barley water?

Can I legally use front facing blue light in the UK?

How would photo IDs work for shapeshifters?

Typesetting a double Over Dot on top of a symbol

Prime joint compound before latex paint?

Why airport relocation isn't done gradually?

extract characters between two commas?

Symmetry in quantum mechanics

What is the meaning of "of trouble" in the following sentence?

Email Account under attack (really) - anything I can do?



Using sed for multiple matches instead matching whole file


How do I combine all lines in a text file into a single line?'tail' command not getting only the new linesUsing Ubuntu command line to replace text in huge fileretain white spaces in fields when using awkdiffrence between two files of different row numbersModify a list: filter it, and rearrange the values in the resultError while using sed fileRemoving multiple space using sedRemove exact matching word using sedWhat's wrong with this backup script?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have file as



0::question#1::
Love
giberrish fdfd

1::anything#2:
Is
repeat

22::anything#3::
Lie


I want to extract



Love
giberish
****
Is
repeat
****
Lie


cat file.txt | sed 's/::n([^n]*)/1/g'



I'm getting file as



0::question#1::
Love

1::anything#2:
Is

22::anything#3::
Lie


On testing regex is matching here
https://regex101.com/



UPDATE
I missed to tell, that file extract is for for multi-line not single line and also i want a deliminator as well. I apologize for trouble



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*//g;/^$/d'



I get output as



Love
giberrish fdfd
Is
repeat 2 4 4
Lie


So I added some deliminator in order to split one record from another



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/***/g;/^$/d'



and got



 ***
Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


To remove top-line i used



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2



new output is



 Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


I want to capture each record using awk i did



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "***" print $1'



I get output



Love
giberrish fdfd


I'm unable to remove last empty line which is same across all fields i tried using pipe to sed with /^$/d didn't work



UPDATE 2
got it working by



``sed 's/^.::.//g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "" print $1' | sed -e '/^$/d'`










share|improve this question



















  • 1





    Try this sed 's/^.*::.*//g' data.txt !

    – George Udosen
    2 days ago











  • It works, splendid, pls have it as answer so i can approve it

    – asadz
    2 days ago











  • This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

    – George Udosen
    2 days ago


















0















I have file as



0::question#1::
Love
giberrish fdfd

1::anything#2:
Is
repeat

22::anything#3::
Lie


I want to extract



Love
giberish
****
Is
repeat
****
Lie


cat file.txt | sed 's/::n([^n]*)/1/g'



I'm getting file as



0::question#1::
Love

1::anything#2:
Is

22::anything#3::
Lie


On testing regex is matching here
https://regex101.com/



UPDATE
I missed to tell, that file extract is for for multi-line not single line and also i want a deliminator as well. I apologize for trouble



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*//g;/^$/d'



I get output as



Love
giberrish fdfd
Is
repeat 2 4 4
Lie


So I added some deliminator in order to split one record from another



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/***/g;/^$/d'



and got



 ***
Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


To remove top-line i used



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2



new output is



 Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


I want to capture each record using awk i did



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "***" print $1'



I get output



Love
giberrish fdfd


I'm unable to remove last empty line which is same across all fields i tried using pipe to sed with /^$/d didn't work



UPDATE 2
got it working by



``sed 's/^.::.//g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "" print $1' | sed -e '/^$/d'`










share|improve this question



















  • 1





    Try this sed 's/^.*::.*//g' data.txt !

    – George Udosen
    2 days ago











  • It works, splendid, pls have it as answer so i can approve it

    – asadz
    2 days ago











  • This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

    – George Udosen
    2 days ago














0












0








0








I have file as



0::question#1::
Love
giberrish fdfd

1::anything#2:
Is
repeat

22::anything#3::
Lie


I want to extract



Love
giberish
****
Is
repeat
****
Lie


cat file.txt | sed 's/::n([^n]*)/1/g'



I'm getting file as



0::question#1::
Love

1::anything#2:
Is

22::anything#3::
Lie


On testing regex is matching here
https://regex101.com/



UPDATE
I missed to tell, that file extract is for for multi-line not single line and also i want a deliminator as well. I apologize for trouble



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*//g;/^$/d'



I get output as



Love
giberrish fdfd
Is
repeat 2 4 4
Lie


So I added some deliminator in order to split one record from another



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/***/g;/^$/d'



and got



 ***
Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


To remove top-line i used



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2



new output is



 Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


I want to capture each record using awk i did



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "***" print $1'



I get output



Love
giberrish fdfd


I'm unable to remove last empty line which is same across all fields i tried using pipe to sed with /^$/d didn't work



UPDATE 2
got it working by



``sed 's/^.::.//g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "" print $1' | sed -e '/^$/d'`










share|improve this question
















I have file as



0::question#1::
Love
giberrish fdfd

1::anything#2:
Is
repeat

22::anything#3::
Lie


I want to extract



Love
giberish
****
Is
repeat
****
Lie


cat file.txt | sed 's/::n([^n]*)/1/g'



I'm getting file as



0::question#1::
Love

1::anything#2:
Is

22::anything#3::
Lie


On testing regex is matching here
https://regex101.com/



UPDATE
I missed to tell, that file extract is for for multi-line not single line and also i want a deliminator as well. I apologize for trouble



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*//g;/^$/d'



I get output as



Love
giberrish fdfd
Is
repeat 2 4 4
Lie


So I added some deliminator in order to split one record from another



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/***/g;/^$/d'



and got



 ***
Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


To remove top-line i used



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2



new output is



 Love
giberrish fdfd
***
Is
repeat 2 4 4
***
Lie


I want to capture each record using awk i did



cat org_op.2019.04.06-09.43.59 | sed 's/^.*::.*/ ***/g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "***" print $1'



I get output



Love
giberrish fdfd


I'm unable to remove last empty line which is same across all fields i tried using pipe to sed with /^$/d didn't work



UPDATE 2
got it working by



``sed 's/^.::.//g;/^$/d' | tail -n +2 | awk 'BEGIN RS = "" ; FS = "" print $1' | sed -e '/^$/d'`







command-line bash sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday







asadz

















asked 2 days ago









asadzasadz

137113




137113







  • 1





    Try this sed 's/^.*::.*//g' data.txt !

    – George Udosen
    2 days ago











  • It works, splendid, pls have it as answer so i can approve it

    – asadz
    2 days ago











  • This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

    – George Udosen
    2 days ago













  • 1





    Try this sed 's/^.*::.*//g' data.txt !

    – George Udosen
    2 days ago











  • It works, splendid, pls have it as answer so i can approve it

    – asadz
    2 days ago











  • This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

    – George Udosen
    2 days ago








1




1





Try this sed 's/^.*::.*//g' data.txt !

– George Udosen
2 days ago





Try this sed 's/^.*::.*//g' data.txt !

– George Udosen
2 days ago













It works, splendid, pls have it as answer so i can approve it

– asadz
2 days ago





It works, splendid, pls have it as answer so i can approve it

– asadz
2 days ago













This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

– George Udosen
2 days ago






This works better sed -e '/^.*::.*/d' -e '/^$/d' data.txt

– George Udosen
2 days ago











2 Answers
2






active

oldest

votes


















1














Use the method of matching lines then remnove those matching lines and then remove the spaces...



sed -e '/^.*::.*/d' -e '/^$/d' data.txt


Result:



Love
Is
Lie


Or a shorter version:



sed -E '/^(.*::.*)?$/d'


Info:




  • '/^.*::.*/d': Match lines with :: and delete them


  • '/^$/d': Remove all blank lines





share|improve this answer




















  • 2





    /::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

    – dessert
    2 days ago







  • 1





    interesting didn't know i could use ? like that!

    – George Udosen
    2 days ago











  • please see update!

    – asadz
    2 days ago


















2














sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie



  • /^[0-9]/d: remove lines starting with a number


  • /^$/d: remove empty lines





share|improve this answer


















  • 1





    To combine both in one expression: sed -E '/^([0-9].*)?$/d'

    – dessert
    2 days ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1131736%2fusing-sed-for-multiple-matches-instead-matching-whole-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Use the method of matching lines then remnove those matching lines and then remove the spaces...



sed -e '/^.*::.*/d' -e '/^$/d' data.txt


Result:



Love
Is
Lie


Or a shorter version:



sed -E '/^(.*::.*)?$/d'


Info:




  • '/^.*::.*/d': Match lines with :: and delete them


  • '/^$/d': Remove all blank lines





share|improve this answer




















  • 2





    /::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

    – dessert
    2 days ago







  • 1





    interesting didn't know i could use ? like that!

    – George Udosen
    2 days ago











  • please see update!

    – asadz
    2 days ago















1














Use the method of matching lines then remnove those matching lines and then remove the spaces...



sed -e '/^.*::.*/d' -e '/^$/d' data.txt


Result:



Love
Is
Lie


Or a shorter version:



sed -E '/^(.*::.*)?$/d'


Info:




  • '/^.*::.*/d': Match lines with :: and delete them


  • '/^$/d': Remove all blank lines





share|improve this answer




















  • 2





    /::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

    – dessert
    2 days ago







  • 1





    interesting didn't know i could use ? like that!

    – George Udosen
    2 days ago











  • please see update!

    – asadz
    2 days ago













1












1








1







Use the method of matching lines then remnove those matching lines and then remove the spaces...



sed -e '/^.*::.*/d' -e '/^$/d' data.txt


Result:



Love
Is
Lie


Or a shorter version:



sed -E '/^(.*::.*)?$/d'


Info:




  • '/^.*::.*/d': Match lines with :: and delete them


  • '/^$/d': Remove all blank lines





share|improve this answer















Use the method of matching lines then remnove those matching lines and then remove the spaces...



sed -e '/^.*::.*/d' -e '/^$/d' data.txt


Result:



Love
Is
Lie


Or a shorter version:



sed -E '/^(.*::.*)?$/d'


Info:




  • '/^.*::.*/d': Match lines with :: and delete them


  • '/^$/d': Remove all blank lines






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









George UdosenGeorge Udosen

21.7k104572




21.7k104572







  • 2





    /::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

    – dessert
    2 days ago







  • 1





    interesting didn't know i could use ? like that!

    – George Udosen
    2 days ago











  • please see update!

    – asadz
    2 days ago












  • 2





    /::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

    – dessert
    2 days ago







  • 1





    interesting didn't know i could use ? like that!

    – George Udosen
    2 days ago











  • please see update!

    – asadz
    2 days ago







2




2





/::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

– dessert
2 days ago






/::/d is a shorter version of your first expression, combined that is: sed -E '/^(.*::.*)?$/d'

– dessert
2 days ago





1




1





interesting didn't know i could use ? like that!

– George Udosen
2 days ago





interesting didn't know i could use ? like that!

– George Udosen
2 days ago













please see update!

– asadz
2 days ago





please see update!

– asadz
2 days ago













2














sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie



  • /^[0-9]/d: remove lines starting with a number


  • /^$/d: remove empty lines





share|improve this answer


















  • 1





    To combine both in one expression: sed -E '/^([0-9].*)?$/d'

    – dessert
    2 days ago















2














sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie



  • /^[0-9]/d: remove lines starting with a number


  • /^$/d: remove empty lines





share|improve this answer


















  • 1





    To combine both in one expression: sed -E '/^([0-9].*)?$/d'

    – dessert
    2 days ago













2












2








2







sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie



  • /^[0-9]/d: remove lines starting with a number


  • /^$/d: remove empty lines





share|improve this answer













sed '/^[0-9]/d; /^$/d' file.txt
Love
Is
Lie



  • /^[0-9]/d: remove lines starting with a number


  • /^$/d: remove empty lines






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Mikael FloraMikael Flora

441117




441117







  • 1





    To combine both in one expression: sed -E '/^([0-9].*)?$/d'

    – dessert
    2 days ago












  • 1





    To combine both in one expression: sed -E '/^([0-9].*)?$/d'

    – dessert
    2 days ago







1




1





To combine both in one expression: sed -E '/^([0-9].*)?$/d'

– dessert
2 days ago





To combine both in one expression: sed -E '/^([0-9].*)?$/d'

– dessert
2 days ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1131736%2fusing-sed-for-multiple-matches-instead-matching-whole-file%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tamil (spriik) Luke uk diar | Nawigatjuun

Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?