AWK: Print first field of every line as identifier for every following field in the corresponding line
I have a input file like this with a blank as field seperator
AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2
The output should look like this:
AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....
The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.
awk
add a comment |
I have a input file like this with a blank as field seperator
AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2
The output should look like this:
AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....
The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.
awk
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago
add a comment |
I have a input file like this with a blank as field seperator
AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2
The output should look like this:
AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....
The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.
awk
I have a input file like this with a blank as field seperator
AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2
The output should look like this:
AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....
The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.
awk
awk
asked 56 mins ago
T-One
586
586
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago
add a comment |
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago
add a comment |
1 Answer
1
active
oldest
votes
Fairly straightforwardly:
awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input
On every line, oop from 2 until the last field (N
umber of F
ields), printing field 1 and the looped field.
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%2f491333%2fawk-print-first-field-of-every-line-as-identifier-for-every-following-field-in%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
Fairly straightforwardly:
awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input
On every line, oop from 2 until the last field (N
umber of F
ields), printing field 1 and the looped field.
add a comment |
Fairly straightforwardly:
awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input
On every line, oop from 2 until the last field (N
umber of F
ields), printing field 1 and the looped field.
add a comment |
Fairly straightforwardly:
awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input
On every line, oop from 2 until the last field (N
umber of F
ields), printing field 1 and the looped field.
Fairly straightforwardly:
awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input
On every line, oop from 2 until the last field (N
umber of F
ields), printing field 1 and the looped field.
answered 50 mins ago
Jeff Schaller
38.7k1053125
38.7k1053125
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f491333%2fawk-print-first-field-of-every-line-as-identifier-for-every-following-field-in%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
Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago