multiple concatenation of strings without writing intermediate files
Clash 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
bash shell-script cat
add a comment |Â
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
bash shell-script cat
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
add a comment |Â
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
bash shell-script cat
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
bash shell-script cat
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
add a comment |Â
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
add a comment |Â
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)'
add a comment |Â
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 toprint
)
note also you can use subshell
( cmd1 arg 1
cmd2 arg for 2
cmd 3 ) > result
which will put output of cmd
s to result
.
add a comment |Â
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
add a comment |Â
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)'
add a comment |Â
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)'
add a comment |Â
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)'
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)'
answered Apr 10 at 10:58
mariaczi
42915
42915
add a comment |Â
add a comment |Â
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 toprint
)
note also you can use subshell
( cmd1 arg 1
cmd2 arg for 2
cmd 3 ) > result
which will put output of cmd
s to result
.
add a comment |Â
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 toprint
)
note also you can use subshell
( cmd1 arg 1
cmd2 arg for 2
cmd 3 ) > result
which will put output of cmd
s to result
.
add a comment |Â
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 toprint
)
note also you can use subshell
( cmd1 arg 1
cmd2 arg for 2
cmd 3 ) > result
which will put output of cmd
s to result
.
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 toprint
)
note also you can use subshell
( cmd1 arg 1
cmd2 arg for 2
cmd 3 ) > result
which will put output of cmd
s to result
.
answered Apr 10 at 10:58
Archemar
18.9k93366
18.9k93366
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited Apr 10 at 16:12
answered Apr 10 at 16:05
ctac_
1,016116
1,016116
add a comment |Â
add a comment |Â
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
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
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
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
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
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