Sed operations are not working or might i am doing it wrong?Working with columns - awk and sedUsing sed/awk...

Can radiation block all wireless communications?

mini sub panel?

Is your maximum jump distance halved by grappling?

Are wands in any sort of book going to be too much like Harry Potter?

When an electron around an atom drops to a lower state, is 100% of the energy converted to a photon?

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Can the Telekinesis spell be used on yourself for the following?

Light Switch Neutrals: Bundle all together?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Why doesn't Dany protect her dragons better?

How would an instant or sorcery with an effect that targets work with Feather?

Why is there a cap on 401k contributions?

Employee is self-centered and affects the team negatively

Crime rates in a post-scarcity economy

Examples where existence is harder than evaluation

Add elements inside Array conditionally in JavaScript

Illegal assignment from Id to List

What's the difference between "ricochet" and "bounce"?

Why does this pattern in powers happen?

Do oversize pulley wheels increase derailleur capacity?

Why are thrust reversers not used down to taxi speeds?

Gift for mentor after his thesis defense?

Company stopped paying my salary. What are my options?

Do these creatures from the Tomb of Annihilation campaign speak Common?



Sed operations are not working or might i am doing it wrong?


Working with columns - awk and sedUsing sed/awk to remove anything after first spaceSeparating names separated by “| character” to individual pairsRemove the multiple comma's from specific column of tab delimited fileand print the words on new lineAWK/SED Remove a specific latex command from the text AND closing bracket behind itRemove a specific latex command from the text AND closing bracket behind itHow can i print unique value of particular column and then print rest of the columns in next lineWhy might sed not make any change to a file?How to delete whitespaces in columns?Using NF with FPAT – what am I doing wrong?






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







1















input: text:



chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053


Desired output:



chrX_143483005-chr6_103649292   chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


Tried:



## No. of Columns in each line.
awk '{print NF}' tt.txt
3
3
3
3
3
## operation to delete the co-ordinates affiliated with comma.
sed -e 's/,chr[A-Z0-9]_[0-9]-chr[A-Z0-9]_[0-9]*.//g' tt.txt


Basically I want to remove co-ordinates just after "," and want to keep only left hands (first one) co-ordinates.



NOTE:
1 In this operation, columns would be the same as input.
2. Comma sepratted co-ordinates are not fixed it can be any columns.
3. Chromosomes can any 1-19, X and Y.










share|improve this question




















  • 1





    Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

    – DopeGhoti
    3 hours ago


















1















input: text:



chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053


Desired output:



chrX_143483005-chr6_103649292   chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


Tried:



## No. of Columns in each line.
awk '{print NF}' tt.txt
3
3
3
3
3
## operation to delete the co-ordinates affiliated with comma.
sed -e 's/,chr[A-Z0-9]_[0-9]-chr[A-Z0-9]_[0-9]*.//g' tt.txt


Basically I want to remove co-ordinates just after "," and want to keep only left hands (first one) co-ordinates.



NOTE:
1 In this operation, columns would be the same as input.
2. Comma sepratted co-ordinates are not fixed it can be any columns.
3. Chromosomes can any 1-19, X and Y.










share|improve this question




















  • 1





    Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

    – DopeGhoti
    3 hours ago














1












1








1








input: text:



chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053


Desired output:



chrX_143483005-chr6_103649292   chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


Tried:



## No. of Columns in each line.
awk '{print NF}' tt.txt
3
3
3
3
3
## operation to delete the co-ordinates affiliated with comma.
sed -e 's/,chr[A-Z0-9]_[0-9]-chr[A-Z0-9]_[0-9]*.//g' tt.txt


Basically I want to remove co-ordinates just after "," and want to keep only left hands (first one) co-ordinates.



NOTE:
1 In this operation, columns would be the same as input.
2. Comma sepratted co-ordinates are not fixed it can be any columns.
3. Chromosomes can any 1-19, X and Y.










share|improve this question
















input: text:



chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053
chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053


Desired output:



chrX_143483005-chr6_103649292   chrX_143483110-chr_6103649147   chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


Tried:



## No. of Columns in each line.
awk '{print NF}' tt.txt
3
3
3
3
3
## operation to delete the co-ordinates affiliated with comma.
sed -e 's/,chr[A-Z0-9]_[0-9]-chr[A-Z0-9]_[0-9]*.//g' tt.txt


Basically I want to remove co-ordinates just after "," and want to keep only left hands (first one) co-ordinates.



NOTE:
1 In this operation, columns would be the same as input.
2. Comma sepratted co-ordinates are not fixed it can be any columns.
3. Chromosomes can any 1-19, X and Y.







linux awk sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 3 hours ago







Rupesh

















asked 3 hours ago









RupeshRupesh

184




184








  • 1





    Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

    – DopeGhoti
    3 hours ago














  • 1





    Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

    – DopeGhoti
    3 hours ago








1




1





Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

– DopeGhoti
3 hours ago





Please, save a cat's life. Rather than cat file | sed 'thing', simply sed 'thing' file.

– DopeGhoti
3 hours ago










1 Answer
1






active

oldest

votes


















3














Simple enough:



$ sed -E 's/,[^ ]+//g' in
chrX_143483005-chr6_103649292 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


The (extended) regular expression /,[^ ]+/ will match any sequence of a comma followed series of characters which are not a space.



The sed command s will substutute any matches of the first argument (in this case, the given expression), with the second argument (in this case, nothing); the g option to the s command says to make that substitution for all matches found rather than merely the first.






share|improve this answer


























  • awesome !! thanks Can you please explain, how its work?

    – Rupesh
    3 hours ago













  • Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

    – Rupesh
    3 hours ago











  • Looking at your edit, I seem to get the desired output with my given command.

    – DopeGhoti
    3 hours ago











  • Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

    – Rupesh
    3 hours ago











  • You could even handle tabs and spaces with /,[^ t]+/ (:

    – DopeGhoti
    3 hours ago












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f517662%2fsed-operations-are-not-working-or-might-i-am-doing-it-wrong%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Simple enough:



$ sed -E 's/,[^ ]+//g' in
chrX_143483005-chr6_103649292 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


The (extended) regular expression /,[^ ]+/ will match any sequence of a comma followed series of characters which are not a space.



The sed command s will substutute any matches of the first argument (in this case, the given expression), with the second argument (in this case, nothing); the g option to the s command says to make that substitution for all matches found rather than merely the first.






share|improve this answer


























  • awesome !! thanks Can you please explain, how its work?

    – Rupesh
    3 hours ago













  • Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

    – Rupesh
    3 hours ago











  • Looking at your edit, I seem to get the desired output with my given command.

    – DopeGhoti
    3 hours ago











  • Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

    – Rupesh
    3 hours ago











  • You could even handle tabs and spaces with /,[^ t]+/ (:

    – DopeGhoti
    3 hours ago
















3














Simple enough:



$ sed -E 's/,[^ ]+//g' in
chrX_143483005-chr6_103649292 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


The (extended) regular expression /,[^ ]+/ will match any sequence of a comma followed series of characters which are not a space.



The sed command s will substutute any matches of the first argument (in this case, the given expression), with the second argument (in this case, nothing); the g option to the s command says to make that substitution for all matches found rather than merely the first.






share|improve this answer


























  • awesome !! thanks Can you please explain, how its work?

    – Rupesh
    3 hours ago













  • Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

    – Rupesh
    3 hours ago











  • Looking at your edit, I seem to get the desired output with my given command.

    – DopeGhoti
    3 hours ago











  • Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

    – Rupesh
    3 hours ago











  • You could even handle tabs and spaces with /,[^ t]+/ (:

    – DopeGhoti
    3 hours ago














3












3








3







Simple enough:



$ sed -E 's/,[^ ]+//g' in
chrX_143483005-chr6_103649292 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


The (extended) regular expression /,[^ ]+/ will match any sequence of a comma followed series of characters which are not a space.



The sed command s will substutute any matches of the first argument (in this case, the given expression), with the second argument (in this case, nothing); the g option to the s command says to make that substitution for all matches found rather than merely the first.






share|improve this answer















Simple enough:



$ sed -E 's/,[^ ]+//g' in
chrX_143483005-chr6_103649292 chrX_143483110-chr_6103649147 chrX_143483004-chr6_103649293
chrX_143483110-chr_6103649147 chrX_143483005-chr6_103649292 0
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147
chrX_143483005-chr6_103649292 0 chrX_143483110-chr_6103649147
0 chrX_143483005-chr6_103649292 chrX_143482988-chr6_103649147


The (extended) regular expression /,[^ ]+/ will match any sequence of a comma followed series of characters which are not a space.



The sed command s will substutute any matches of the first argument (in this case, the given expression), with the second argument (in this case, nothing); the g option to the s command says to make that substitution for all matches found rather than merely the first.







share|improve this answer














share|improve this answer



share|improve this answer








edited 3 hours ago

























answered 3 hours ago









DopeGhotiDopeGhoti

47.7k56194




47.7k56194













  • awesome !! thanks Can you please explain, how its work?

    – Rupesh
    3 hours ago













  • Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

    – Rupesh
    3 hours ago











  • Looking at your edit, I seem to get the desired output with my given command.

    – DopeGhoti
    3 hours ago











  • Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

    – Rupesh
    3 hours ago











  • You could even handle tabs and spaces with /,[^ t]+/ (:

    – DopeGhoti
    3 hours ago



















  • awesome !! thanks Can you please explain, how its work?

    – Rupesh
    3 hours ago













  • Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

    – Rupesh
    3 hours ago











  • Looking at your edit, I seem to get the desired output with my given command.

    – DopeGhoti
    3 hours ago











  • Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

    – Rupesh
    3 hours ago











  • You could even handle tabs and spaces with /,[^ t]+/ (:

    – DopeGhoti
    3 hours ago

















awesome !! thanks Can you please explain, how its work?

– Rupesh
3 hours ago







awesome !! thanks Can you please explain, how its work?

– Rupesh
3 hours ago















Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

– Rupesh
3 hours ago





Not working with this line: 0 chrX_143483005-chr6_103649292,chrX_143483110-chr6_103649131 chrX_143482988-chr6_103649147,chrX_143483004-chr6_103649293,chrX_143483110-chr6_103649291,chrX_143483110-chr6_103649053 it removes last column.

– Rupesh
3 hours ago













Looking at your edit, I seem to get the desired output with my given command.

– DopeGhoti
3 hours ago





Looking at your edit, I seem to get the desired output with my given command.

– DopeGhoti
3 hours ago













Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

– Rupesh
3 hours ago





Ok, now i get it. I have tab separated columns and here you are replacing "space", so i just added sed -E 's/,[^t]+//g' input. its working now thanks for your gentle reply

– Rupesh
3 hours ago













You could even handle tabs and spaces with /,[^ t]+/ (:

– DopeGhoti
3 hours ago





You could even handle tabs and spaces with /,[^ t]+/ (:

– DopeGhoti
3 hours ago


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • 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%2funix.stackexchange.com%2fquestions%2f517662%2fsed-operations-are-not-working-or-might-i-am-doing-it-wrong%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

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...