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?
When an electron around an atom drops to a lower state, is 100% of the energy converted to a photon?
How can it be that ssh somename works, while nslookup somename does not?
Program for finding longest run of zeros from a list of 100 random integers which are either 0 or 1
Company stopped paying my salary. What are my options?
What are these pads?
Should one save up to purchase a house/condo or maximize their 401(k) first?
GLM: Modelling proportional data - account for variation in total sample size
logo selection for poster presentation
What is the oldest instrument ever?
Visual Studio Code download existing code
Identity of a supposed anonymous referee revealed through "Description" of the report
As a small race with a heavy weapon, does enlage remove the disadvantage?
Sed operations are not working or might i am doing it wrong?
What should I use to get rid of some kind of weed in my onions
How to append code verbatim to .bashrc?
Align a table column at a specific symbol
Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?
Is there an application which does HTTP PUT?
Why does this pattern in powers happen?
Why did Missandei say this?
I'm attempting to understand my 401k match and how much I need to contribute to maximize the match
Can a character shove an enemy who is already prone?
When I add a cylinder, it doesn't even show up on my screen at all
Which "exotic salt" can lower water's freezing point by 70 °C?
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;
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
add a comment |
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
1
Please, save a cat's life. Rather thancat file | sed 'thing'
, simplysed 'thing' file
.
– DopeGhoti
4 hours ago
add a comment |
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
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
linux awk sed
edited 4 hours ago
Rupesh
asked 4 hours ago
RupeshRupesh
184
184
1
Please, save a cat's life. Rather thancat file | sed 'thing'
, simplysed 'thing' file
.
– DopeGhoti
4 hours ago
add a comment |
1
Please, save a cat's life. Rather thancat file | sed 'thing'
, simplysed 'thing' file
.
– DopeGhoti
4 hours ago
1
1
Please, save a cat's life. Rather than
cat file | sed 'thing'
, simply sed 'thing' file
.– DopeGhoti
4 hours ago
Please, save a cat's life. Rather than
cat file | sed 'thing'
, simply sed 'thing' file
.– DopeGhoti
4 hours ago
add a comment |
1 Answer
1
active
oldest
votes
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.
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 hours ago
You could even handle tabs and spaces with/,[^ t]+/
(:
– DopeGhoti
4 hours ago
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 hours ago
You could even handle tabs and spaces with/,[^ t]+/
(:
– DopeGhoti
4 hours ago
add a comment |
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.
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 hours ago
You could even handle tabs and spaces with/,[^ t]+/
(:
– DopeGhoti
4 hours ago
add a comment |
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.
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.
edited 4 hours ago
answered 4 hours ago
DopeGhotiDopeGhoti
47.7k56194
47.7k56194
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 hours ago
You could even handle tabs and spaces with/,[^ t]+/
(:
– DopeGhoti
4 hours ago
add a comment |
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 hours ago
You could even handle tabs and spaces with/,[^ t]+/
(:
– DopeGhoti
4 hours ago
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 hours ago
awesome !! thanks Can you please explain, how its work?
– Rupesh
4 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
4 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
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 hours ago
Looking at your edit, I seem to get the desired output with my given command.
– DopeGhoti
4 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
4 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
4 hours ago
You could even handle tabs and spaces with
/,[^ t]+/
(:– DopeGhoti
4 hours ago
You could even handle tabs and spaces with
/,[^ t]+/
(:– DopeGhoti
4 hours ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Please, save a cat's life. Rather than
cat file | sed 'thing'
, simplysed 'thing' file
.– DopeGhoti
4 hours ago