Iterate print for each line in output The Next CEO of Stack OverflowShell programming, avoiding tempfilesprint all matches or replace all strings in a BIG file which is NOT line organised (no line separators)Print a line in stdout that matches an expression if the output contains another expressionMatch lines beginning with the same pattern in two text filesExtracting multiple lines from each file in directory, editing text and appending file name for each matching linereplace the empty fields from the output of “grep” with a stringFor a large directory, create a variable of the filenames which include lines which include the text string stored in another variablePrint text before and after match, from a specific beginning and to an ending stringPrint data between two lines (only if “range end” exists) from a text filePrint file Word for Word on keypress
Proper way to express "He disappeared them"
Why the difference in type-inference over the as-pattern in two similar function definitions?
WOW air has ceased operation, can I get my tickets refunded?
The past simple of "gaslight" – "gaslighted" or "gaslit"?
Why does standard notation not preserve intervals (visually)
Legal workarounds for testamentary trust perceived as unfair
How to prove a simple equation?
Grabbing quick drinks
What flight has the highest ratio of timezone difference to flight time?
Can we say or write : "No, it'sn't"?
The exact meaning of 'Mom made me a sandwich'
How to avoid supervisors with prejudiced views?
Is wanting to ask what to write an indication that you need to change your story?
Do I need to write [sic] when a number is less than 10 but isn't written out?
RigExpert AA-35 - Interpreting The Information
Won the lottery - how do I keep the money?
What happened in Rome, when the western empire "fell"?
Is it okay to majorly distort historical facts while writing a fiction story?
A small doubt about the dominated convergence theorem
Running a General Election and the European Elections together
Does increasing your ability score affect your main stat?
Poetry, calligrams and TikZ/PStricks challenge
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
TikZ: How to reverse arrow direction without switching start/end point?
Iterate print for each line in output
The Next CEO of Stack OverflowShell programming, avoiding tempfilesprint all matches or replace all strings in a BIG file which is NOT line organised (no line separators)Print a line in stdout that matches an expression if the output contains another expressionMatch lines beginning with the same pattern in two text filesExtracting multiple lines from each file in directory, editing text and appending file name for each matching linereplace the empty fields from the output of “grep” with a stringFor a large directory, create a variable of the filenames which include lines which include the text string stored in another variablePrint text before and after match, from a specific beginning and to an ending stringPrint data between two lines (only if “range end” exists) from a text filePrint file Word for Word on keypress
I want to print uvuveve
at finish each line, for each output into while statement, as below:
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
This is my code:
var1="somedata..."
var2="anotherdata..."
while read -u3 w1; read -u4 w2; do
echo "$w1;$w2" >> $file
done 3<<< "$var1" 4<<<"$var2"
var1, var2 print multiple occurrences of a file, so there are many outputs by these variables. I tried to add uvuveve
word like this way:
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
while read -u3 w1; read -u4 w2; read -u5 w3; do
echo "$w1;$w2;$w3" >> $file
done 3<<< "$var1" 4<<<"$var2" 5<<<"$string"
Essentially, I need a print of the word in each line, for each occurrence founded.
Adding Details:
Var1
& var2
retrieve lines of occurrences that a file contains, and then put into variables
Literally the lines are:
var1=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 51-65 | sed -e 's! !/!g')
var2=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 67-71 | sed -e 's/://g')
linux text-processing awk ksh
add a comment |
I want to print uvuveve
at finish each line, for each output into while statement, as below:
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
This is my code:
var1="somedata..."
var2="anotherdata..."
while read -u3 w1; read -u4 w2; do
echo "$w1;$w2" >> $file
done 3<<< "$var1" 4<<<"$var2"
var1, var2 print multiple occurrences of a file, so there are many outputs by these variables. I tried to add uvuveve
word like this way:
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
while read -u3 w1; read -u4 w2; read -u5 w3; do
echo "$w1;$w2;$w3" >> $file
done 3<<< "$var1" 4<<<"$var2" 5<<<"$string"
Essentially, I need a print of the word in each line, for each occurrence founded.
Adding Details:
Var1
& var2
retrieve lines of occurrences that a file contains, and then put into variables
Literally the lines are:
var1=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 51-65 | sed -e 's! !/!g')
var2=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 67-71 | sed -e 's/://g')
linux text-processing awk ksh
2
Does replacingecho "$w1;$w2;$w3"
withecho "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.
– John1024
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
1
Does the data in your two variablesvar1
andvar2
come from a file? Could you give a real example of input and output?
– Kusalananda♦
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago
add a comment |
I want to print uvuveve
at finish each line, for each output into while statement, as below:
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
This is my code:
var1="somedata..."
var2="anotherdata..."
while read -u3 w1; read -u4 w2; do
echo "$w1;$w2" >> $file
done 3<<< "$var1" 4<<<"$var2"
var1, var2 print multiple occurrences of a file, so there are many outputs by these variables. I tried to add uvuveve
word like this way:
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
while read -u3 w1; read -u4 w2; read -u5 w3; do
echo "$w1;$w2;$w3" >> $file
done 3<<< "$var1" 4<<<"$var2" 5<<<"$string"
Essentially, I need a print of the word in each line, for each occurrence founded.
Adding Details:
Var1
& var2
retrieve lines of occurrences that a file contains, and then put into variables
Literally the lines are:
var1=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 51-65 | sed -e 's! !/!g')
var2=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 67-71 | sed -e 's/://g')
linux text-processing awk ksh
I want to print uvuveve
at finish each line, for each output into while statement, as below:
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
var1;var2;uvuveve
This is my code:
var1="somedata..."
var2="anotherdata..."
while read -u3 w1; read -u4 w2; do
echo "$w1;$w2" >> $file
done 3<<< "$var1" 4<<<"$var2"
var1, var2 print multiple occurrences of a file, so there are many outputs by these variables. I tried to add uvuveve
word like this way:
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
while read -u3 w1; read -u4 w2; read -u5 w3; do
echo "$w1;$w2;$w3" >> $file
done 3<<< "$var1" 4<<<"$var2" 5<<<"$string"
Essentially, I need a print of the word in each line, for each occurrence founded.
Adding Details:
Var1
& var2
retrieve lines of occurrences that a file contains, and then put into variables
Literally the lines are:
var1=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 51-65 | sed -e 's! !/!g')
var2=$(grep -A12 -B12 "$tofind" $findlogs | grep Date | cut -c 67-71 | sed -e 's/://g')
linux text-processing awk ksh
linux text-processing awk ksh
edited 2 days ago
Mareyes
asked 2 days ago
MareyesMareyes
13113
13113
2
Does replacingecho "$w1;$w2;$w3"
withecho "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.
– John1024
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
1
Does the data in your two variablesvar1
andvar2
come from a file? Could you give a real example of input and output?
– Kusalananda♦
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago
add a comment |
2
Does replacingecho "$w1;$w2;$w3"
withecho "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.
– John1024
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
1
Does the data in your two variablesvar1
andvar2
come from a file? Could you give a real example of input and output?
– Kusalananda♦
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago
2
2
Does replacing
echo "$w1;$w2;$w3"
with echo "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.– John1024
2 days ago
Does replacing
echo "$w1;$w2;$w3"
with echo "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.– John1024
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
1
1
Does the data in your two variables
var1
and var2
come from a file? Could you give a real example of input and output?– Kusalananda♦
2 days ago
Does the data in your two variables
var1
and var2
come from a file? Could you give a real example of input and output?– Kusalananda♦
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
Since you just have plain text in variables, redirecting them into a while-read loop seems ridiculously over-complicated.
What's wrong with
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
echo "$var1;$var2;$string"
# or
printf '%s;%s;%sn' "$var1" "$var2" "$string"
If you actually have files, then you do need a loop. If we have
$ cat file1
a
b
c
$ cat file2
1
2
3
then
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3<file1 4<file2
a;1;uvuveve
b;2;uvuveve
c;3;uvuveve
Going back to your edit: use Process Substitutions
# don't repeat yourself
dates=$(grep -A12 -B12 "$tofind" $findlogs | grep Date)
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3< <(echo "$dates" | cut -c 51-65 | sed -e 's! !/!g')
4< <(echo "$dates" | cut -c 67-71 | sed -e 's/://g')
add a comment |
Does this do what you want?
#!/usr/bin/env bash
IFS=$'n'; var1=( $( ... your command here ... ) );
IFS=$'n'; var2=( $( ... your command here ... ) );
for i in $!var1[@]; do
echo $arr1[$i];$arr2[$i];uvuveve
done
It assumes that var1
and var2
have the same amount of lines.
Basically:
- We turn your command into a variable that is an array. source
- Then we iterate the array (source) adding the variables together and your extra string.
New contributor
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
add a comment |
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
);
);
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%2funix.stackexchange.com%2fquestions%2f509296%2fiterate-print-for-each-line-in-output%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you just have plain text in variables, redirecting them into a while-read loop seems ridiculously over-complicated.
What's wrong with
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
echo "$var1;$var2;$string"
# or
printf '%s;%s;%sn' "$var1" "$var2" "$string"
If you actually have files, then you do need a loop. If we have
$ cat file1
a
b
c
$ cat file2
1
2
3
then
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3<file1 4<file2
a;1;uvuveve
b;2;uvuveve
c;3;uvuveve
Going back to your edit: use Process Substitutions
# don't repeat yourself
dates=$(grep -A12 -B12 "$tofind" $findlogs | grep Date)
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3< <(echo "$dates" | cut -c 51-65 | sed -e 's! !/!g')
4< <(echo "$dates" | cut -c 67-71 | sed -e 's/://g')
add a comment |
Since you just have plain text in variables, redirecting them into a while-read loop seems ridiculously over-complicated.
What's wrong with
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
echo "$var1;$var2;$string"
# or
printf '%s;%s;%sn' "$var1" "$var2" "$string"
If you actually have files, then you do need a loop. If we have
$ cat file1
a
b
c
$ cat file2
1
2
3
then
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3<file1 4<file2
a;1;uvuveve
b;2;uvuveve
c;3;uvuveve
Going back to your edit: use Process Substitutions
# don't repeat yourself
dates=$(grep -A12 -B12 "$tofind" $findlogs | grep Date)
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3< <(echo "$dates" | cut -c 51-65 | sed -e 's! !/!g')
4< <(echo "$dates" | cut -c 67-71 | sed -e 's/://g')
add a comment |
Since you just have plain text in variables, redirecting them into a while-read loop seems ridiculously over-complicated.
What's wrong with
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
echo "$var1;$var2;$string"
# or
printf '%s;%s;%sn' "$var1" "$var2" "$string"
If you actually have files, then you do need a loop. If we have
$ cat file1
a
b
c
$ cat file2
1
2
3
then
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3<file1 4<file2
a;1;uvuveve
b;2;uvuveve
c;3;uvuveve
Going back to your edit: use Process Substitutions
# don't repeat yourself
dates=$(grep -A12 -B12 "$tofind" $findlogs | grep Date)
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3< <(echo "$dates" | cut -c 51-65 | sed -e 's! !/!g')
4< <(echo "$dates" | cut -c 67-71 | sed -e 's/://g')
Since you just have plain text in variables, redirecting them into a while-read loop seems ridiculously over-complicated.
What's wrong with
var1="somedata..."
var2="anotherdata..."
string="uvuveve"
echo "$var1;$var2;$string"
# or
printf '%s;%s;%sn' "$var1" "$var2" "$string"
If you actually have files, then you do need a loop. If we have
$ cat file1
a
b
c
$ cat file2
1
2
3
then
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3<file1 4<file2
a;1;uvuveve
b;2;uvuveve
c;3;uvuveve
Going back to your edit: use Process Substitutions
# don't repeat yourself
dates=$(grep -A12 -B12 "$tofind" $findlogs | grep Date)
string="uvuveve"
while IFS= read -r -u3 a; read -r -u4 b; do
printf '%s;%s;%sn' "$a" "$b" "$string"
done 3< <(echo "$dates" | cut -c 51-65 | sed -e 's! !/!g')
4< <(echo "$dates" | cut -c 67-71 | sed -e 's/://g')
edited yesterday
answered 2 days ago
glenn jackmanglenn jackman
52.9k573114
52.9k573114
add a comment |
add a comment |
Does this do what you want?
#!/usr/bin/env bash
IFS=$'n'; var1=( $( ... your command here ... ) );
IFS=$'n'; var2=( $( ... your command here ... ) );
for i in $!var1[@]; do
echo $arr1[$i];$arr2[$i];uvuveve
done
It assumes that var1
and var2
have the same amount of lines.
Basically:
- We turn your command into a variable that is an array. source
- Then we iterate the array (source) adding the variables together and your extra string.
New contributor
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
add a comment |
Does this do what you want?
#!/usr/bin/env bash
IFS=$'n'; var1=( $( ... your command here ... ) );
IFS=$'n'; var2=( $( ... your command here ... ) );
for i in $!var1[@]; do
echo $arr1[$i];$arr2[$i];uvuveve
done
It assumes that var1
and var2
have the same amount of lines.
Basically:
- We turn your command into a variable that is an array. source
- Then we iterate the array (source) adding the variables together and your extra string.
New contributor
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
add a comment |
Does this do what you want?
#!/usr/bin/env bash
IFS=$'n'; var1=( $( ... your command here ... ) );
IFS=$'n'; var2=( $( ... your command here ... ) );
for i in $!var1[@]; do
echo $arr1[$i];$arr2[$i];uvuveve
done
It assumes that var1
and var2
have the same amount of lines.
Basically:
- We turn your command into a variable that is an array. source
- Then we iterate the array (source) adding the variables together and your extra string.
New contributor
Does this do what you want?
#!/usr/bin/env bash
IFS=$'n'; var1=( $( ... your command here ... ) );
IFS=$'n'; var2=( $( ... your command here ... ) );
for i in $!var1[@]; do
echo $arr1[$i];$arr2[$i];uvuveve
done
It assumes that var1
and var2
have the same amount of lines.
Basically:
- We turn your command into a variable that is an array. source
- Then we iterate the array (source) adding the variables together and your extra string.
New contributor
New contributor
answered 2 days ago
KyleKyle
165
165
New contributor
New contributor
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
add a comment |
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
I have other script with arrays, and your solution was useful. Thanks, Kyle!
– Mareyes
yesterday
add a comment |
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.
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%2funix.stackexchange.com%2fquestions%2f509296%2fiterate-print-for-each-line-in-output%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
2
Does replacing
echo "$w1;$w2;$w3"
withecho "$w1;$w2;$string"
solve the problem? If not, please provide enough input data (and corresponding desired output) so that we can understand what you are actually trying to do. See How to create a Minimal, Complete, and Verifiable example.– John1024
2 days ago
Adding the $w3 varaible (string) only add one time the string.
– Mareyes
2 days ago
Yes, that is why I suggested that you change the code as per my comment.
– John1024
2 days ago
1
Does the data in your two variables
var1
andvar2
come from a file? Could you give a real example of input and output?– Kusalananda♦
2 days ago
@Kusalananda here goes.
– Mareyes
2 days ago