Why do this awk script print the original file too?calling awk script from C++ stops at “bozo :wait_for”awk - counting content of filesawk print column $3 if $2==a specific value?Linux shell scripting - Simple awk script issuePrint out all remaining variables in awkAwk not working inside bash scriptAWK doesn't work in Bash Scriptprint lines with blank in file using awkUNIX AWK script - memory exhaustedWhy is using variables in awk scripts breaking the counter?
How to save PDFs from web for offline reading on an iPad?
What is a realistic time needed to get a properly trained army?
Can I disable a battery powered device by reversing half of its batteries?
Do Milankovitch Cycles fully explain climate change?
Honourable versus Right Honourable Members
Are CO₂ tire cartridges reusable for multiple tires?
Is there a standard terminology for female equivalents of terms such as 'Kingdom' and if so, what are the most common terms?
„nichts wie raus hier“ - explanation based on the literal meaning?
How to add a theme preprocess function for published state?
My employer wants me to do a work of 6 months in just 2 months
What is Japanese Language Stack Exchange called in Japanese?
How to split a string by the third .(dot) delimiter
What does "synoptic" mean in avionics?
Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time
Why should I always enable compiler warnings?
Kingdom Map and Travel Pace
How to find a missing person abroad
How could a imperial dynasty keep a loose collection of pirates, raiders, etc unified?
Is the union of a chain of elementary embeddings elementary?
Do any aircraft carry boats?
Random point on a sphere
Exact Brexit date and consequences
Are there any instances of members of different Hogwarts houses coupling up and marrying each other?
How can I protect myself in case of a human attack like the murders of the hikers Jespersen and Ueland in Morocco?
Why do this awk script print the original file too?
calling awk script from C++ stops at “bozo :wait_for”awk - counting content of filesawk print column $3 if $2==a specific value?Linux shell scripting - Simple awk script issuePrint out all remaining variables in awkAwk not working inside bash scriptAWK doesn't work in Bash Scriptprint lines with blank in file using awkUNIX AWK script - memory exhaustedWhy is using variables in awk scripts breaking the counter?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have following script:
ascript2.awk
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1]=a[$1] ";" $2 " : " $3
END
for (x in a) print x,a[x]
When I let it run, it prints also the original intput file. Why?
When I make a bash script like this it works fine:
merge
#!/bin/bash
awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1
Input:
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Outputs:
$ ./merge t.txt
Money ; 9:test3
Affe ; 3:test 5:test2
$ ./ascript2.awk t.txt
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Money ; 9 : test3
Affe ; 3 : test; 5 : test2
awk
add a comment |
I have following script:
ascript2.awk
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1]=a[$1] ";" $2 " : " $3
END
for (x in a) print x,a[x]
When I let it run, it prints also the original intput file. Why?
When I make a bash script like this it works fine:
merge
#!/bin/bash
awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1
Input:
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Outputs:
$ ./merge t.txt
Money ; 9:test3
Affe ; 3:test 5:test2
$ ./ascript2.awk t.txt
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Money ; 9 : test3
Affe ; 3 : test; 5 : test2
awk
add a comment |
I have following script:
ascript2.awk
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1]=a[$1] ";" $2 " : " $3
END
for (x in a) print x,a[x]
When I let it run, it prints also the original intput file. Why?
When I make a bash script like this it works fine:
merge
#!/bin/bash
awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1
Input:
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Outputs:
$ ./merge t.txt
Money ; 9:test3
Affe ; 3:test 5:test2
$ ./ascript2.awk t.txt
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Money ; 9 : test3
Affe ; 3 : test; 5 : test2
awk
I have following script:
ascript2.awk
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1]=a[$1] ";" $2 " : " $3
END
for (x in a) print x,a[x]
When I let it run, it prints also the original intput file. Why?
When I make a bash script like this it works fine:
merge
#!/bin/bash
awk -F' *: *' 'a[$1]=a[$1] (a[$1]?" \ " :" ; ") $2 ":" $3 END for (x in a) print x,a[x]' $1
Input:
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Outputs:
$ ./merge t.txt
Money ; 9:test3
Affe ; 3:test 5:test2
$ ./ascript2.awk t.txt
Affe : 3 : test
Affe : 5 : test2
Money : 9 : test3
Money ; 9 : test3
Affe ; 3 : test; 5 : test2
awk
awk
edited Mar 28 at 9:21
oguz ismail
12.2k7 gold badges18 silver badges37 bronze badges
12.2k7 gold badges18 silver badges37 bronze badges
asked Mar 28 at 9:00
Walter SchrabmairWalter Schrabmair
4571 gold badge6 silver badges18 bronze badges
4571 gold badge6 silver badges18 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In ascript2.awk
, a[$1]=a[$1] ";" $2 " : " $3
should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
)
So your script should look this:
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1] = a[$1] ";" $2 " : " $3
END for (x in a) print x, a[x]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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/4.0/"u003ecc by-sa 4.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%2fstackoverflow.com%2fquestions%2f55393584%2fwhy-do-this-awk-script-print-the-original-file-too%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
In ascript2.awk
, a[$1]=a[$1] ";" $2 " : " $3
should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
)
So your script should look this:
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1] = a[$1] ";" $2 " : " $3
END for (x in a) print x, a[x]
add a comment |
In ascript2.awk
, a[$1]=a[$1] ";" $2 " : " $3
should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
)
So your script should look this:
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1] = a[$1] ";" $2 " : " $3
END for (x in a) print x, a[x]
add a comment |
In ascript2.awk
, a[$1]=a[$1] ";" $2 " : " $3
should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
)
So your script should look this:
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1] = a[$1] ";" $2 " : " $3
END for (x in a) print x, a[x]
In ascript2.awk
, a[$1]=a[$1] ";" $2 " : " $3
should be enclosed in curly braces, otherwise it will be interpreted as a condition with no action, and any condition without an action will print the line if and only the condition is met. (See: what is the meaning of 1 at the end of awk script
)
So your script should look this:
#!/usr/bin/awk -f
BEGIN FS=":"
a[$1] = a[$1] ";" $2 " : " $3
END for (x in a) print x, a[x]
answered Mar 28 at 9:20
oguz ismailoguz ismail
12.2k7 gold badges18 silver badges37 bronze badges
12.2k7 gold badges18 silver badges37 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55393584%2fwhy-do-this-awk-script-print-the-original-file-too%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