AWK fields filtering misses the first field Announcing the arrival of Valued Associate #679:...

Does the universe have a fixed centre of mass?

What is "Lambda" in Heston's original paper on stochastic volatility models?

Do i imagine the linear (straight line) homotopy in a correct way?

Statistical analysis applied to methods coming out of Machine Learning

Why does BitLocker not use RSA?

Is it OK to use the testing sample to compare algorithms?

How to resize main filesystem

How to achieve cat-like agility?

What is the proper term for etching or digging of wall to hide conduit of cables

What are some likely causes to domain member PC losing contact to domain controller?

French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

Why do C and C++ allow the expression (int) + 4*5?

Random body shuffle every night—can we still function?

Understanding piped commands in GNU/Linux

How does TikZ render an arc?

Determine whether an integer is a palindrome

Did pre-Columbian Americans know the spherical shape of the Earth?

Is there a spell that can create a permanent fire?

Improvising over quartal voicings

Table formatting with tabularx?

Google .dev domain strangely redirects to https

Russian equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

The test team as an enemy of development? And how can this be avoided?

How do you cope with tons of web fonts when copying and pasting from web pages?



AWK fields filtering misses the first field



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionAwk: expanding first field along the columnAwk field separator bug?AWK : the ' ' as field separatorWhy awk says “syntax error” for the comma I placed between the two patterns?Text filtering using awkAwk: remove first few fields from CSVawk command to check condition from first field of first row and second field of first rowprocessing multiple files with awk problemawk to retrieve the first field report from atqUsing NF with FPAT – what am I doing wrong?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I'm writing AWK code to pick some fields from an input file, and trim columns with pre-defined fields to pick, etc.



The input file looks like:



    stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,wheelchair_boarding,platform_code
"228055","228055","Pacific Hwy After Murray St","-33.0036096083102","151.685565693411","","","0",""

"228054","228054","Pacific Hwy Opp Ntaba Rd","-33.0061947514409","151.684612196188","","","0",""

"287146","287146","Flint St At Oxford St","-33.3923728991621","148.014977179488","","","0",""

"228056","228056","Pacific Hwy At South St","-32.9998469180446","151.685494632801","","","0",""


And my simplified code to exercise the problem I have:



#! /usr/bin/awk -f
BEGIN {
# 0. AWK init
FS = ","
OFS = ","
}

NR == 1 {
for (i = 1; i <= NF; i++) {
# headerIdx["stop_id"] = 1, etc
headerIdx[$i] = i
print "key: " $i ", value: " headerIdx[$i]
}
print "stop_id - " headerIdx["stop_id"] "stop_code - " headerIdx["stop_code"] ", stop_name - " headerIdx["stop_name"] ", stop_lat - " headerIdx["stop_lat"]
}


When I run the script like (for example): "./awk-test.awk stops.txt" (where the data file name is stops.txt and the script file name is awk-test.awk), I got an output:




key: stop_id, value: 1
key: stop_code, value: 2
key: stop_name, value: 3
key: stop_lat, value: 4
key: stop_lon, value: 5
key: location_type, value: 6
key: parent_station, value: 7
key: wheelchair_boarding, value: 8
key: platform_code, value: 9



stop_id - stop_code - 2, stop_name - 3, stop_lat - 4




I would expect the stop_id in the last line has a value 1, but it has nothing.



Why my expectation is not reasonable and how to make it spit out the missing value 1? (GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
, and I can switch to gawk if it fixes this problem)










share|improve this question







New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Can you make sure that first line doesn't have spaces at the beginning?

    – Prvt_Yadv
    16 mins ago


















0















I'm writing AWK code to pick some fields from an input file, and trim columns with pre-defined fields to pick, etc.



The input file looks like:



    stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,wheelchair_boarding,platform_code
"228055","228055","Pacific Hwy After Murray St","-33.0036096083102","151.685565693411","","","0",""

"228054","228054","Pacific Hwy Opp Ntaba Rd","-33.0061947514409","151.684612196188","","","0",""

"287146","287146","Flint St At Oxford St","-33.3923728991621","148.014977179488","","","0",""

"228056","228056","Pacific Hwy At South St","-32.9998469180446","151.685494632801","","","0",""


And my simplified code to exercise the problem I have:



#! /usr/bin/awk -f
BEGIN {
# 0. AWK init
FS = ","
OFS = ","
}

NR == 1 {
for (i = 1; i <= NF; i++) {
# headerIdx["stop_id"] = 1, etc
headerIdx[$i] = i
print "key: " $i ", value: " headerIdx[$i]
}
print "stop_id - " headerIdx["stop_id"] "stop_code - " headerIdx["stop_code"] ", stop_name - " headerIdx["stop_name"] ", stop_lat - " headerIdx["stop_lat"]
}


When I run the script like (for example): "./awk-test.awk stops.txt" (where the data file name is stops.txt and the script file name is awk-test.awk), I got an output:




key: stop_id, value: 1
key: stop_code, value: 2
key: stop_name, value: 3
key: stop_lat, value: 4
key: stop_lon, value: 5
key: location_type, value: 6
key: parent_station, value: 7
key: wheelchair_boarding, value: 8
key: platform_code, value: 9



stop_id - stop_code - 2, stop_name - 3, stop_lat - 4




I would expect the stop_id in the last line has a value 1, but it has nothing.



Why my expectation is not reasonable and how to make it spit out the missing value 1? (GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
, and I can switch to gawk if it fixes this problem)










share|improve this question







New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • Can you make sure that first line doesn't have spaces at the beginning?

    – Prvt_Yadv
    16 mins ago














0












0








0








I'm writing AWK code to pick some fields from an input file, and trim columns with pre-defined fields to pick, etc.



The input file looks like:



    stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,wheelchair_boarding,platform_code
"228055","228055","Pacific Hwy After Murray St","-33.0036096083102","151.685565693411","","","0",""

"228054","228054","Pacific Hwy Opp Ntaba Rd","-33.0061947514409","151.684612196188","","","0",""

"287146","287146","Flint St At Oxford St","-33.3923728991621","148.014977179488","","","0",""

"228056","228056","Pacific Hwy At South St","-32.9998469180446","151.685494632801","","","0",""


And my simplified code to exercise the problem I have:



#! /usr/bin/awk -f
BEGIN {
# 0. AWK init
FS = ","
OFS = ","
}

NR == 1 {
for (i = 1; i <= NF; i++) {
# headerIdx["stop_id"] = 1, etc
headerIdx[$i] = i
print "key: " $i ", value: " headerIdx[$i]
}
print "stop_id - " headerIdx["stop_id"] "stop_code - " headerIdx["stop_code"] ", stop_name - " headerIdx["stop_name"] ", stop_lat - " headerIdx["stop_lat"]
}


When I run the script like (for example): "./awk-test.awk stops.txt" (where the data file name is stops.txt and the script file name is awk-test.awk), I got an output:




key: stop_id, value: 1
key: stop_code, value: 2
key: stop_name, value: 3
key: stop_lat, value: 4
key: stop_lon, value: 5
key: location_type, value: 6
key: parent_station, value: 7
key: wheelchair_boarding, value: 8
key: platform_code, value: 9



stop_id - stop_code - 2, stop_name - 3, stop_lat - 4




I would expect the stop_id in the last line has a value 1, but it has nothing.



Why my expectation is not reasonable and how to make it spit out the missing value 1? (GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
, and I can switch to gawk if it fixes this problem)










share|improve this question







New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I'm writing AWK code to pick some fields from an input file, and trim columns with pre-defined fields to pick, etc.



The input file looks like:



    stop_id,stop_code,stop_name,stop_lat,stop_lon,location_type,parent_station,wheelchair_boarding,platform_code
"228055","228055","Pacific Hwy After Murray St","-33.0036096083102","151.685565693411","","","0",""

"228054","228054","Pacific Hwy Opp Ntaba Rd","-33.0061947514409","151.684612196188","","","0",""

"287146","287146","Flint St At Oxford St","-33.3923728991621","148.014977179488","","","0",""

"228056","228056","Pacific Hwy At South St","-32.9998469180446","151.685494632801","","","0",""


And my simplified code to exercise the problem I have:



#! /usr/bin/awk -f
BEGIN {
# 0. AWK init
FS = ","
OFS = ","
}

NR == 1 {
for (i = 1; i <= NF; i++) {
# headerIdx["stop_id"] = 1, etc
headerIdx[$i] = i
print "key: " $i ", value: " headerIdx[$i]
}
print "stop_id - " headerIdx["stop_id"] "stop_code - " headerIdx["stop_code"] ", stop_name - " headerIdx["stop_name"] ", stop_lat - " headerIdx["stop_lat"]
}


When I run the script like (for example): "./awk-test.awk stops.txt" (where the data file name is stops.txt and the script file name is awk-test.awk), I got an output:




key: stop_id, value: 1
key: stop_code, value: 2
key: stop_name, value: 3
key: stop_lat, value: 4
key: stop_lon, value: 5
key: location_type, value: 6
key: parent_station, value: 7
key: wheelchair_boarding, value: 8
key: platform_code, value: 9



stop_id - stop_code - 2, stop_name - 3, stop_lat - 4




I would expect the stop_id in the last line has a value 1, but it has nothing.



Why my expectation is not reasonable and how to make it spit out the missing value 1? (GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
, and I can switch to gawk if it fixes this problem)







awk






share|improve this question







New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 53 mins ago









oz.stigoz.stig

1




1




New contributor




oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






oz.stig is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • Can you make sure that first line doesn't have spaces at the beginning?

    – Prvt_Yadv
    16 mins ago



















  • Can you make sure that first line doesn't have spaces at the beginning?

    – Prvt_Yadv
    16 mins ago

















Can you make sure that first line doesn't have spaces at the beginning?

– Prvt_Yadv
16 mins ago





Can you make sure that first line doesn't have spaces at the beginning?

– Prvt_Yadv
16 mins ago










0






active

oldest

votes












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
});


}
});






oz.stig is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513747%2fawk-fields-filtering-misses-the-first-field%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








oz.stig is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















oz.stig is a new contributor. Be nice, and check out our Code of Conduct.













oz.stig is a new contributor. Be nice, and check out our Code of Conduct.












oz.stig 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f513747%2fawk-fields-filtering-misses-the-first-field%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...