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