multiple concatenation of strings without writing intermediate files

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I would like to extract parts of some files and concatenate them into another but without writing an intermediate file.



For instance:



$ cat textExample.txt 
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'
marvelled
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)'
answer
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)'
blessed


In order to concatenate the sentences together, one file could be written:



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'| tr "n" " " > intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)' | tr "n" " " >> intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)' >> intermediate.txt
$ cat intermediate.txt
marvelled answer blessed


or multiple awk commands could be used (although I could not remove the newline):



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9); print substr($0, 77, 6); print substr($0, 189, 7)' 
marvelled
answer
blessed


I was wondering whether cat could be used directly to concatenate the different words together without relying on an intermediate file, something like:



$ cat first word | cat second word | cat third word 
first second third


Thank you







share|improve this question




















  • How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
    – Kusalananda
    Apr 10 at 10:54










  • Please show what output you want to see.
    – glenn jackman
    Apr 10 at 13:26














up vote
0
down vote

favorite












I would like to extract parts of some files and concatenate them into another but without writing an intermediate file.



For instance:



$ cat textExample.txt 
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'
marvelled
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)'
answer
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)'
blessed


In order to concatenate the sentences together, one file could be written:



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'| tr "n" " " > intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)' | tr "n" " " >> intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)' >> intermediate.txt
$ cat intermediate.txt
marvelled answer blessed


or multiple awk commands could be used (although I could not remove the newline):



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9); print substr($0, 77, 6); print substr($0, 189, 7)' 
marvelled
answer
blessed


I was wondering whether cat could be used directly to concatenate the different words together without relying on an intermediate file, something like:



$ cat first word | cat second word | cat third word 
first second third


Thank you







share|improve this question




















  • How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
    – Kusalananda
    Apr 10 at 10:54










  • Please show what output you want to see.
    – glenn jackman
    Apr 10 at 13:26












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I would like to extract parts of some files and concatenate them into another but without writing an intermediate file.



For instance:



$ cat textExample.txt 
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'
marvelled
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)'
answer
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)'
blessed


In order to concatenate the sentences together, one file could be written:



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'| tr "n" " " > intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)' | tr "n" " " >> intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)' >> intermediate.txt
$ cat intermediate.txt
marvelled answer blessed


or multiple awk commands could be used (although I could not remove the newline):



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9); print substr($0, 77, 6); print substr($0, 189, 7)' 
marvelled
answer
blessed


I was wondering whether cat could be used directly to concatenate the different words together without relying on an intermediate file, something like:



$ cat first word | cat second word | cat third word 
first second third


Thank you







share|improve this question












I would like to extract parts of some files and concatenate them into another but without writing an intermediate file.



For instance:



$ cat textExample.txt 
Much I marvelled this ungainly fowl to hear discourse so plainly,
Though its answer little meaning- little relevancy bore;
For we cannot help agreeing that no living human being
Ever yet was blessed with seeing bird above his chamber door-
Bird or beast upon the sculptured bust above his chamber door,
With such name as "Nevermore."
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'
marvelled
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)'
answer
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)'
blessed


In order to concatenate the sentences together, one file could be written:



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9)'| tr "n" " " > intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 77, 6)' | tr "n" " " >> intermediate.txt
$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 189, 7)' >> intermediate.txt
$ cat intermediate.txt
marvelled answer blessed


or multiple awk commands could be used (although I could not remove the newline):



$ cat textExample.txt | tr -d "n" | awk 'NR==1' | awk 'print substr($0, 8, 9); print substr($0, 77, 6); print substr($0, 189, 7)' 
marvelled
answer
blessed


I was wondering whether cat could be used directly to concatenate the different words together without relying on an intermediate file, something like:



$ cat first word | cat second word | cat third word 
first second third


Thank you









share|improve this question











share|improve this question




share|improve this question










asked Apr 10 at 10:39









Gigiux

92




92











  • How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
    – Kusalananda
    Apr 10 at 10:54










  • Please show what output you want to see.
    – glenn jackman
    Apr 10 at 13:26
















  • How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
    – Kusalananda
    Apr 10 at 10:54










  • Please show what output you want to see.
    – glenn jackman
    Apr 10 at 13:26















How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
– Kusalananda
Apr 10 at 10:54




How do you know what words to pick out? Is it the third word on every line (maybe not, you're skipping the third line)?
– Kusalananda
Apr 10 at 10:54












Please show what output you want to see.
– glenn jackman
Apr 10 at 13:26




Please show what output you want to see.
– glenn jackman
Apr 10 at 13:26










3 Answers
3






active

oldest

votes

















up vote
0
down vote













This works for me if I understand you correctly:



cat textExample.txt | tr -d "n" | awk 'print substr($0, 8, 9) " " substr($0, 77, 6) " " substr($0, 189, 7)'





share|improve this answer



























    up vote
    0
    down vote













    I don't get what you intend.



    Yet try :



     ... | tr -d 'n' |
    awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'


    which give with your input



    tr -d 'n' < se | awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'
    marvelled answer blessed


    • have a look at printf, which by default do not end with a newline (contrary to print )

    note also you can use subshell



    ( cmd1 arg 1
    cmd2 arg for 2
    cmd 3 ) > result


    which will put output of cmds to result.






    share|improve this answer



























      up vote
      0
      down vote













      With bash



      cat extract_words.sh

      #!/bin/bash
      concat=" "
      min=$(($6+$7))
      while read line
      do
      concat="$concat$line"
      if test "$#concat" -ge "$min" ; then
      break
      fi
      done < "$1"
      echo "$concat:$2:$3" "$concat:$4:$5" "$concat:$6:$7"


      You call it like that



      ./extract_words.sh "textExample.txt" 8 9 77 6 189 7





      share|improve this answer






















        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',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        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%2f436738%2fmultiple-concatenation-of-strings-without-writing-intermediate-files%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote













        This works for me if I understand you correctly:



        cat textExample.txt | tr -d "n" | awk 'print substr($0, 8, 9) " " substr($0, 77, 6) " " substr($0, 189, 7)'





        share|improve this answer
























          up vote
          0
          down vote













          This works for me if I understand you correctly:



          cat textExample.txt | tr -d "n" | awk 'print substr($0, 8, 9) " " substr($0, 77, 6) " " substr($0, 189, 7)'





          share|improve this answer






















            up vote
            0
            down vote










            up vote
            0
            down vote









            This works for me if I understand you correctly:



            cat textExample.txt | tr -d "n" | awk 'print substr($0, 8, 9) " " substr($0, 77, 6) " " substr($0, 189, 7)'





            share|improve this answer












            This works for me if I understand you correctly:



            cat textExample.txt | tr -d "n" | awk 'print substr($0, 8, 9) " " substr($0, 77, 6) " " substr($0, 189, 7)'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 10 at 10:58









            mariaczi

            42915




            42915






















                up vote
                0
                down vote













                I don't get what you intend.



                Yet try :



                 ... | tr -d 'n' |
                awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'


                which give with your input



                tr -d 'n' < se | awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'
                marvelled answer blessed


                • have a look at printf, which by default do not end with a newline (contrary to print )

                note also you can use subshell



                ( cmd1 arg 1
                cmd2 arg for 2
                cmd 3 ) > result


                which will put output of cmds to result.






                share|improve this answer
























                  up vote
                  0
                  down vote













                  I don't get what you intend.



                  Yet try :



                   ... | tr -d 'n' |
                  awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'


                  which give with your input



                  tr -d 'n' < se | awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'
                  marvelled answer blessed


                  • have a look at printf, which by default do not end with a newline (contrary to print )

                  note also you can use subshell



                  ( cmd1 arg 1
                  cmd2 arg for 2
                  cmd 3 ) > result


                  which will put output of cmds to result.






                  share|improve this answer






















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    I don't get what you intend.



                    Yet try :



                     ... | tr -d 'n' |
                    awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'


                    which give with your input



                    tr -d 'n' < se | awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'
                    marvelled answer blessed


                    • have a look at printf, which by default do not end with a newline (contrary to print )

                    note also you can use subshell



                    ( cmd1 arg 1
                    cmd2 arg for 2
                    cmd 3 ) > result


                    which will put output of cmds to result.






                    share|improve this answer












                    I don't get what you intend.



                    Yet try :



                     ... | tr -d 'n' |
                    awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'


                    which give with your input



                    tr -d 'n' < se | awk 'printf "%s %s %sn", substr($0, 8, 9),substr($0, 77, 6),substr($0, 189, 7)'
                    marvelled answer blessed


                    • have a look at printf, which by default do not end with a newline (contrary to print )

                    note also you can use subshell



                    ( cmd1 arg 1
                    cmd2 arg for 2
                    cmd 3 ) > result


                    which will put output of cmds to result.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 10 at 10:58









                    Archemar

                    18.9k93366




                    18.9k93366




















                        up vote
                        0
                        down vote













                        With bash



                        cat extract_words.sh

                        #!/bin/bash
                        concat=" "
                        min=$(($6+$7))
                        while read line
                        do
                        concat="$concat$line"
                        if test "$#concat" -ge "$min" ; then
                        break
                        fi
                        done < "$1"
                        echo "$concat:$2:$3" "$concat:$4:$5" "$concat:$6:$7"


                        You call it like that



                        ./extract_words.sh "textExample.txt" 8 9 77 6 189 7





                        share|improve this answer


























                          up vote
                          0
                          down vote













                          With bash



                          cat extract_words.sh

                          #!/bin/bash
                          concat=" "
                          min=$(($6+$7))
                          while read line
                          do
                          concat="$concat$line"
                          if test "$#concat" -ge "$min" ; then
                          break
                          fi
                          done < "$1"
                          echo "$concat:$2:$3" "$concat:$4:$5" "$concat:$6:$7"


                          You call it like that



                          ./extract_words.sh "textExample.txt" 8 9 77 6 189 7





                          share|improve this answer
























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            With bash



                            cat extract_words.sh

                            #!/bin/bash
                            concat=" "
                            min=$(($6+$7))
                            while read line
                            do
                            concat="$concat$line"
                            if test "$#concat" -ge "$min" ; then
                            break
                            fi
                            done < "$1"
                            echo "$concat:$2:$3" "$concat:$4:$5" "$concat:$6:$7"


                            You call it like that



                            ./extract_words.sh "textExample.txt" 8 9 77 6 189 7





                            share|improve this answer














                            With bash



                            cat extract_words.sh

                            #!/bin/bash
                            concat=" "
                            min=$(($6+$7))
                            while read line
                            do
                            concat="$concat$line"
                            if test "$#concat" -ge "$min" ; then
                            break
                            fi
                            done < "$1"
                            echo "$concat:$2:$3" "$concat:$4:$5" "$concat:$6:$7"


                            You call it like that



                            ./extract_words.sh "textExample.txt" 8 9 77 6 189 7






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Apr 10 at 16:12

























                            answered Apr 10 at 16:05









                            ctac_

                            1,016116




                            1,016116






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436738%2fmultiple-concatenation-of-strings-without-writing-intermediate-files%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?