Comma separated words into new linesExpanding comma-separated list into separate linesAwk/grep/sed get comma...
Rail-to-rail op-amp only reaches 90% of VCC, works sometimes, not everytime
Confused with atmospheric pressure equals plastic balloon’s inner pressure
How (un)safe is it to ride barefoot?
Should I refuse to be named as co-author of a low quality paper?
What do you call the action of "describing events as they happen" like sports anchors do?
Assigning function to function pointer, const argument correctness?
Canada travel to US using Global Entry
Was planting UN flag on Moon ever discussed?
Could a person damage a jet airliner - from the outside - with their bare hands?
Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?
The origin of the Russian proverb about two hares
Make Gimbap cutter
Convert only certain words to lowercase
Proving that a Russian cryptographic standard is too structured
What STL algorithm can determine if exactly one item in a container satisfies a predicate?
What is the logic behind charging tax _in the form of money_ for owning property when the property does not produce money?
C++ logging library
What would be the way to say "just saying" in German? (Not the literal translation)
Is Jesus the last Prophet?
How far would a landing Airbus A380 go until it stops with no brakes?
Grep Match and extract
Do you have to have figures when playing D&D?
Was Self-modifying-code possible just using BASIC?
Do you need to let the DM know when you are multiclassing?
Comma separated words into new lines
Expanding comma-separated list into separate linesAwk/grep/sed get comma separated list of numbers from lines of textChange script to use whiptail instead of zenityjoin multiple lines based on column1Assigning files key words to easily find them laterProcessing table with comma separated values in different columnsMerge jq output into a comma separated stringGrep Ternary Curl ReponsePassing the output of a command to another in one lineHow to convert a 3 column csv file into a table (or matrix)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Hi I have an input file looks like this
N1518 AMP,AUG,AZM,CHL
N1520 AZM,NAL
N1524 AMP,NAL,STR
......
I'm trying to convert it to
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1520 NAL
N1524 AMP
N1524 NAL
N1524 STR
....
Is there an one liner to do this?
command-line
New contributor
add a comment |
Hi I have an input file looks like this
N1518 AMP,AUG,AZM,CHL
N1520 AZM,NAL
N1524 AMP,NAL,STR
......
I'm trying to convert it to
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1520 NAL
N1524 AMP
N1524 NAL
N1524 STR
....
Is there an one liner to do this?
command-line
New contributor
add a comment |
Hi I have an input file looks like this
N1518 AMP,AUG,AZM,CHL
N1520 AZM,NAL
N1524 AMP,NAL,STR
......
I'm trying to convert it to
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1520 NAL
N1524 AMP
N1524 NAL
N1524 STR
....
Is there an one liner to do this?
command-line
New contributor
Hi I have an input file looks like this
N1518 AMP,AUG,AZM,CHL
N1520 AZM,NAL
N1524 AMP,NAL,STR
......
I'm trying to convert it to
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1520 NAL
N1524 AMP
N1524 NAL
N1524 STR
....
Is there an one liner to do this?
command-line
command-line
New contributor
New contributor
New contributor
asked 1 hour ago
user357073user357073
31
31
New contributor
New contributor
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use awk with multiple separators, and then iterate over fields to print the columns.
awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file
Explanation:
-F'[ ,]+'
: This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.
for (i=2;i<=NF;i++)
: loops over all columns starting from the second one, because we have to print the first column repeatedly.
printf "%s %sn",$1,$i;
: prints a line with the first column and the ith column
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
add a comment |
Try this,
awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1524 AMP
N1524 NAL
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins 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
});
}
});
user357073 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f523921%2fcomma-separated-words-into-new-lines%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
You can use awk with multiple separators, and then iterate over fields to print the columns.
awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file
Explanation:
-F'[ ,]+'
: This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.
for (i=2;i<=NF;i++)
: loops over all columns starting from the second one, because we have to print the first column repeatedly.
printf "%s %sn",$1,$i;
: prints a line with the first column and the ith column
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
add a comment |
You can use awk with multiple separators, and then iterate over fields to print the columns.
awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file
Explanation:
-F'[ ,]+'
: This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.
for (i=2;i<=NF;i++)
: loops over all columns starting from the second one, because we have to print the first column repeatedly.
printf "%s %sn",$1,$i;
: prints a line with the first column and the ith column
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
add a comment |
You can use awk with multiple separators, and then iterate over fields to print the columns.
awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file
Explanation:
-F'[ ,]+'
: This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.
for (i=2;i<=NF;i++)
: loops over all columns starting from the second one, because we have to print the first column repeatedly.
printf "%s %sn",$1,$i;
: prints a line with the first column and the ith column
You can use awk with multiple separators, and then iterate over fields to print the columns.
awk -F'[ ,]+' '{for (i=2;i<=NF;i++) {printf "%s %sn",$1,$i;}}' file
Explanation:
-F'[ ,]+'
: This tells awk to use both space and comma as the field separator. It also tells it to consider consecutive separators as a single separator.
for (i=2;i<=NF;i++)
: loops over all columns starting from the second one, because we have to print the first column repeatedly.
printf "%s %sn",$1,$i;
: prints a line with the first column and the ith column
answered 1 hour ago
amisaxamisax
1,636615
1,636615
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
add a comment |
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
Works. Just replaced the space with tab since it is tab separated file. Nice explanation.
– user357073
54 mins ago
add a comment |
Try this,
awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1524 AMP
N1524 NAL
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
add a comment |
Try this,
awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1524 AMP
N1524 NAL
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
add a comment |
Try this,
awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1524 AMP
N1524 NAL
Try this,
awk -F '[t,]' '{for (i=2;i<NF;i++) print $1"t"$i}' file
N1518 AMP
N1518 AUG
N1518 AZM
N1518 CHL
N1520 AZM
N1524 AMP
N1524 NAL
edited 57 mins ago
answered 1 hour ago
msp9011msp9011
5,08244269
5,08244269
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
add a comment |
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
1
1
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
Thanks. It works perfectly. It is tab separated so I replaced the space with a tab ` '[t ,]'`
– user357073
56 mins ago
add a comment |
user357073 is a new contributor. Be nice, and check out our Code of Conduct.
user357073 is a new contributor. Be nice, and check out our Code of Conduct.
user357073 is a new contributor. Be nice, and check out our Code of Conduct.
user357073 is a new contributor. Be nice, and check out our Code of Conduct.
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%2f523921%2fcomma-separated-words-into-new-lines%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