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?
The unknown and unexplained in science fiction
Where do 5 or more U.S. counties meet in a single point?
Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?
Can the president of the United States be guilty of insider trading?
Company stopped paying my salary. What are my options?
How is it believable that Euron could so easily pull off this ambush?
Why doesn't a particle exert force on itself?
Why doesn't increasing the temperature of something like wood or paper set them on fire?
Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?
Using mean length and mean weight to calculate mean BMI?
Gift for mentor after his thesis defense?
Two (probably) equal real numbers which are not proved to be equal?
Illegal assignment from Id to List
Can a character shove an enemy who is already prone?
How to start your Starctaft II games vs AI immediatly?
Opposite party turned away from voting when ballot is all opposing party
I'm attempting to understand my 401k match and how much I need to contribute to maximize the match
Is it a good idea to copy a trader when investing?
How to adjust Venn Diagram for A^c and A - B
Is there an idiom that means "revealing a secret unintentionally"?
Add elements inside Array conditionally in JavaScript
And now you see it II (the B side)
Align a table column at a specific symbol
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
5 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 5 hours ago
RupeshRupesh
184
184
1
Please, save a cat's life. Rather thancat file | sed 'thing'
, simplysed 'thing' file
.
– DopeGhoti
5 hours ago
add a comment |
1
Please, save a cat's life. Rather thancat file | sed 'thing'
, simplysed 'thing' file
.
– DopeGhoti
5 hours ago
1
1
Please, save a cat's life. Rather than
cat file | sed 'thing'
, simply sed 'thing' file
.– DopeGhoti
5 hours ago
Please, save a cat's life. Rather than
cat file | sed 'thing'
, simply sed 'thing' file
.– DopeGhoti
5 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
5 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
5 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
5 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 5 hours ago
DopeGhotiDopeGhoti
47.7k56194
47.7k56194
awesome !! thanks Can you please explain, how its work?
– Rupesh
5 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
5 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
5 hours ago
awesome !! thanks Can you please explain, how its work?
– Rupesh
5 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
5 hours ago