Assign every word from a line to a variableHow can I list the second to last word found in a sequence of statements in awkawk + print lines from the first line until match wordReplace the first word of each line with its MD5use awk with input from a variableHow to assign a multiple line string value to a variable with indentation in a shell script?read the file and assign the values to another fileUnix variable not able to store sql query outputawk: print one line per field-1 value (distinct) where difference “field-2 - field-3” is minimumAdding a column to the start of a .tsv file in a loop?Writing a AWK script by taking the input file as an argument
Asked to Not Use Transactions and to Use A Workaround to Simulate One
Is there any reason to concentrate on the Thunderous Smite spell after using its effects?
What was the ultimate objective of The Party in 1984?
How to make a bold sparkline in Google Sheets?
What's the benefit of prohibiting the use of techniques/language constructs that have not been taught?
Shouldn't countries like Russia and Canada support global warming?
How can I say "I want to" as a short response, omitting the main verb?
Impossible Scrabble Words
Why does the speed of sound decrease at high altitudes although the air density decreases?
What is the mathematical notation for rounding a given number to the nearest integer?
Seven Places at Once - Another Google Earth Challenge?
Permutations in Disguise
If I want an interpretable model, are there methods other than Linear Regression?
Is my sink P-trap too low?
How to control the output voltage of a solid state relay
Bit one of the Intel 8080's Flags register
2000s space film where an alien species has almost wiped out the human race in a war
Is "you will become a subject matter expert" code for "you'll be working on your own 100% of the time"?
Why is it called a stateful and a stateless firewall?
Insight into cavity resonators
How much would a 1 foot tall human weigh?
What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)
Work done by spring force
Are there any “Third Order” acronyms used in space exploration?
Assign every word from a line to a variable
How can I list the second to last word found in a sequence of statements in awkawk + print lines from the first line until match wordReplace the first word of each line with its MD5use awk with input from a variableHow to assign a multiple line string value to a variable with indentation in a shell script?read the file and assign the values to another fileUnix variable not able to store sql query outputawk: print one line per field-1 value (distinct) where difference “field-2 - field-3” is minimumAdding a column to the start of a .tsv file in a loop?Writing a AWK script by taking the input file as an argument
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop
The value of each of those 4 variable I want to use further in my shell program.
Thanks for the help.
Few of the lines from the file:
Ta Cr Mo W
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo
shell-script awk
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment
|
I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop
The value of each of those 4 variable I want to use further in my shell program.
Thanks for the help.
Few of the lines from the file:
Ta Cr Mo W
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo
shell-script awk
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why awk? I mean, awk does this automatically:awk 'print $3' filewill print the 3rd field. Is that what you mean, or do you want to do this in the shell?
– terdon♦
8 hours ago
add a comment
|
I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop
The value of each of those 4 variable I want to use further in my shell program.
Thanks for the help.
Few of the lines from the file:
Ta Cr Mo W
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo
shell-script awk
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am very new to shell programming.
I have a file named quaternary_splitted.csv on macOS.
Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest some kind of awk command in for loop
The value of each of those 4 variable I want to use further in my shell program.
Thanks for the help.
Few of the lines from the file:
Ta Cr Mo W
Nb Cr Mo W
Nb Ta Mo W
Nb Ta Cr W
Nb Ta Cr Mo
shell-script awk
shell-script awk
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 8 hours ago
terdon♦
143k35 gold badges294 silver badges472 bronze badges
143k35 gold badges294 silver badges472 bronze badges
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 8 hours ago
SufyanSufyan
162 bronze badges
162 bronze badges
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Sufyan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Why awk? I mean, awk does this automatically:awk 'print $3' filewill print the 3rd field. Is that what you mean, or do you want to do this in the shell?
– terdon♦
8 hours ago
add a comment
|
1
Why awk? I mean, awk does this automatically:awk 'print $3' filewill print the 3rd field. Is that what you mean, or do you want to do this in the shell?
– terdon♦
8 hours ago
1
1
Why awk? I mean, awk does this automatically:
awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?– terdon♦
8 hours ago
Why awk? I mean, awk does this automatically:
awk 'print $3' file will print the 3rd field. Is that what you mean, or do you want to do this in the shell?– terdon♦
8 hours ago
add a comment
|
1 Answer
1
active
oldest
votes
You can do this with a while read loop like so:
while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv
This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.
The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:
col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`
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/4.0/"u003ecc by-sa 4.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
);
);
Sufyan is a new contributor. Be nice, and check out our Code of Conduct.
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%2f541752%2fassign-every-word-from-a-line-to-a-variable%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
You can do this with a while read loop like so:
while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv
This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.
The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:
col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`
add a comment
|
You can do this with a while read loop like so:
while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv
This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.
The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:
col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`
add a comment
|
You can do this with a while read loop like so:
while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv
This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.
The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:
col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`
You can do this with a while read loop like so:
while read -r col1 col2 col3 col4 trash; do
something with "$col1"
something with "$col2"
something with "$col3"
something with "$col4"
done < /path/to/quaternary_splitted.csv
This will read through each line of quaternary_splitted.csv and set the first column to col1, second column to col2, etc.
The trash parameter is used to catch anything that may be in your file and unwanted.
Say you had a line: Nb Ta Cr W what is this doing here?. Without trash you would get:
col1=Nb
col2=Ta
col3=Cr
col4='W what is this doing here?`
answered 8 hours ago
Jesse_bJesse_b
18.9k3 gold badges46 silver badges88 bronze badges
18.9k3 gold badges46 silver badges88 bronze badges
add a comment
|
add a comment
|
Sufyan is a new contributor. Be nice, and check out our Code of Conduct.
Sufyan is a new contributor. Be nice, and check out our Code of Conduct.
Sufyan is a new contributor. Be nice, and check out our Code of Conduct.
Sufyan is a new contributor. Be nice, and check out our Code of Conduct.
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%2f541752%2fassign-every-word-from-a-line-to-a-variable%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
1
Why awk? I mean, awk does this automatically:
awk 'print $3' filewill print the 3rd field. Is that what you mean, or do you want to do this in the shell?– terdon♦
8 hours ago