AWK - “for loop” inside of new line printUsing awk to parse AIX's lsuser output in stanza formatUse FOR...

Uncommanded roll at high speed

Humans meet a distant alien species. How do they standardize? - Units of Measure

Can non-English-speaking characters use wordplay specific to English?

Is there an evolutionary advantage to having two heads?

Is there a rule that prohibits us from using 2 possessives in a row?

Creating Fictional Slavic Place Names

Self-Preservation: How to DM NPCs that Love Living?

etoolbox: AtBeginEnvironment is not At Begin Environment

Understanding STM32 datasheet regarding decoupling capacitors

The deliberate use of misleading terminology

Why is there a need to modify system call tables in linux?

When a current flow in an inductor is interrupted, what limits the voltage rise?

Do creatures all have the same statistics upon being reanimated via the Animate Dead spell?

Why do Russians call their women expensive ("дорогая")?

What does "Marchentalender" on the front of a postcard mean?

How can I grammatically understand "Wir über uns"?

If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?

What does it mean when you think without speaking?

Why were the Night's Watch required to be celibate?

How was Apollo supposed to rendezvous in the case of a lunar abort?

Modern approach to radio buttons

What to do if opponent has poor hygiene?

Could IPv6 make NAT / port numbers redundant?

How to capture more stars?



AWK - “for loop” inside of new line print


Using awk to parse AIX's lsuser output in stanza formatUse FOR Loop inside END block of awk commandhow to print a new line in awkSeparating names separated by “| character” to individual pairsPrint concat vars inside loopawk if loop not able to printHow do I append text from one line, to the end of another?run commands inside awk before printUse awk to print only the IP and OPEN ports fieldAwk command inside a for loop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I'm searching how to put for loop inside "print" - I've managed how to get all information what I need from log file but if I use "for loop" after print then each new information is given in new line. I know that is calling print each time so... how to print all in new line?
For example this:



cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " "} {for(i=12; i<=NF; i++) print $i}'


Give me that output:



66.249.65.172 - [29/May/2019:02:48:20 +0200]
"Mozilla/5.0
(compatible;
Googlebot/2.1;
+http://www.google.com/bot.html)"


But when I want to pass at end what I found between 12 col and NF:



cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " " for(i=12; i<=NF; i++) " " $i}'


Then I get only:



66.249.65.172 - [29/May/2019:02:48:20 +0200]


I'm heading to output like:



66.249.65.172 - [29/May/2019:02:48:20 +0200] "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"









share|improve this question































    2















    I'm searching how to put for loop inside "print" - I've managed how to get all information what I need from log file but if I use "for loop" after print then each new information is given in new line. I know that is calling print each time so... how to print all in new line?
    For example this:



    cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " "} {for(i=12; i<=NF; i++) print $i}'


    Give me that output:



    66.249.65.172 - [29/May/2019:02:48:20 +0200]
    "Mozilla/5.0
    (compatible;
    Googlebot/2.1;
    +http://www.google.com/bot.html)"


    But when I want to pass at end what I found between 12 col and NF:



    cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " " for(i=12; i<=NF; i++) " " $i}'


    Then I get only:



    66.249.65.172 - [29/May/2019:02:48:20 +0200]


    I'm heading to output like:



    66.249.65.172 - [29/May/2019:02:48:20 +0200] "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"









    share|improve this question



























      2












      2








      2








      I'm searching how to put for loop inside "print" - I've managed how to get all information what I need from log file but if I use "for loop" after print then each new information is given in new line. I know that is calling print each time so... how to print all in new line?
      For example this:



      cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " "} {for(i=12; i<=NF; i++) print $i}'


      Give me that output:



      66.249.65.172 - [29/May/2019:02:48:20 +0200]
      "Mozilla/5.0
      (compatible;
      Googlebot/2.1;
      +http://www.google.com/bot.html)"


      But when I want to pass at end what I found between 12 col and NF:



      cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " " for(i=12; i<=NF; i++) " " $i}'


      Then I get only:



      66.249.65.172 - [29/May/2019:02:48:20 +0200]


      I'm heading to output like:



      66.249.65.172 - [29/May/2019:02:48:20 +0200] "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"









      share|improve this question
















      I'm searching how to put for loop inside "print" - I've managed how to get all information what I need from log file but if I use "for loop" after print then each new information is given in new line. I know that is calling print each time so... how to print all in new line?
      For example this:



      cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " "} {for(i=12; i<=NF; i++) print $i}'


      Give me that output:



      66.249.65.172 - [29/May/2019:02:48:20 +0200]
      "Mozilla/5.0
      (compatible;
      Googlebot/2.1;
      +http://www.google.com/bot.html)"


      But when I want to pass at end what I found between 12 col and NF:



      cat /var/log/apache2/domlogs/xxxx/xxxx.com* | awk -F " " '{print $1 " - " $4 " " $5 " " for(i=12; i<=NF; i++) " " $i}'


      Then I get only:



      66.249.65.172 - [29/May/2019:02:48:20 +0200]


      I'm heading to output like:



      66.249.65.172 - [29/May/2019:02:48:20 +0200] "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"






      awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 48 mins ago







      TheTanadu

















      asked 55 mins ago









      TheTanaduTheTanadu

      228




      228






















          1 Answer
          1






          active

          oldest

          votes


















          2














          You need to use printf() over print because the latter by default embeds a newline after the string provided. Modify your code to use printf with format specifiers for each of the strings.



          awk '{ printf "%s - %s  %s ", $1, $4, $5 } 
          { for(i=12; i<=NF; i++) printf "%s ", $i; printf "n" }'





          share|improve this answer


























          • Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

            – TheTanadu
            31 mins ago












          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521665%2fawk-for-loop-inside-of-new-line-print%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









          2














          You need to use printf() over print because the latter by default embeds a newline after the string provided. Modify your code to use printf with format specifiers for each of the strings.



          awk '{ printf "%s - %s  %s ", $1, $4, $5 } 
          { for(i=12; i<=NF; i++) printf "%s ", $i; printf "n" }'





          share|improve this answer


























          • Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

            – TheTanadu
            31 mins ago
















          2














          You need to use printf() over print because the latter by default embeds a newline after the string provided. Modify your code to use printf with format specifiers for each of the strings.



          awk '{ printf "%s - %s  %s ", $1, $4, $5 } 
          { for(i=12; i<=NF; i++) printf "%s ", $i; printf "n" }'





          share|improve this answer


























          • Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

            – TheTanadu
            31 mins ago














          2












          2








          2







          You need to use printf() over print because the latter by default embeds a newline after the string provided. Modify your code to use printf with format specifiers for each of the strings.



          awk '{ printf "%s - %s  %s ", $1, $4, $5 } 
          { for(i=12; i<=NF; i++) printf "%s ", $i; printf "n" }'





          share|improve this answer















          You need to use printf() over print because the latter by default embeds a newline after the string provided. Modify your code to use printf with format specifiers for each of the strings.



          awk '{ printf "%s - %s  %s ", $1, $4, $5 } 
          { for(i=12; i<=NF; i++) printf "%s ", $i; printf "n" }'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 29 mins ago

























          answered 35 mins ago









          InianInian

          6,1901633




          6,1901633













          • Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

            – TheTanadu
            31 mins ago



















          • Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

            – TheTanadu
            31 mins ago

















          Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

          – TheTanadu
          31 mins ago





          Thank you so much - that's did the trick - only I've added extra space here "%s - %s %s " because output had lack of it

          – TheTanadu
          31 mins ago


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f521665%2fawk-for-loop-inside-of-new-line-print%23new-answer', 'question_page');
          }
          );

          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







          Popular posts from this blog

          Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

          Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

          Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...