awk condition for 30th column of a line is not working











up vote
-1
down vote

favorite
1












My Input file looks like below,



1,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,,kapeta,,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,C
2,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,20181006T11:57:13+0100,,vsuser,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,H
1,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,,enrruac,,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,C
4,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,20181007T22:25:13+0100,,vsuser,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,H


i want to print only the line that are starting with '1' and ends with 'C', so i am trying with below command,



awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt


but i am not getting any output.










share|improve this question




















  • 2




    With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
    – Cyrus
    2 days ago

















up vote
-1
down vote

favorite
1












My Input file looks like below,



1,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,,kapeta,,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,C
2,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,20181006T11:57:13+0100,,vsuser,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,H
1,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,,enrruac,,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,C
4,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,20181007T22:25:13+0100,,vsuser,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,H


i want to print only the line that are starting with '1' and ends with 'C', so i am trying with below command,



awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt


but i am not getting any output.










share|improve this question




















  • 2




    With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
    – Cyrus
    2 days ago















up vote
-1
down vote

favorite
1









up vote
-1
down vote

favorite
1






1





My Input file looks like below,



1,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,,kapeta,,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,C
2,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,20181006T11:57:13+0100,,vsuser,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,H
1,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,,enrruac,,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,C
4,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,20181007T22:25:13+0100,,vsuser,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,H


i want to print only the line that are starting with '1' and ends with 'C', so i am trying with below command,



awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt


but i am not getting any output.










share|improve this question















My Input file looks like below,



1,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,,kapeta,,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,C
2,,B4,3000,Rushab,UNI,20130919T22:45:05+0100,20190930T23:59:59+0100,20181006T11:57:13+0100,,vsuser,6741948090816,2285917436,971078887,1283538808965528,20181102_20001,,,,,,,,,,,,,,,H
1,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,,enrruac,,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,C
4,,F1,100000,RAWBANK,UNI,20180416T15:25:00+0100,20190416T23:59:59+0100,20181007T22:25:13+0100,,vsuser,7522609506635,3101315044,998445487,1290161608965816,20181102_20001,,,,,,,,,,,,,,,H


i want to print only the line that are starting with '1' and ends with 'C', so i am trying with below command,



awk -F, '$1=='1' && $31=='C'{print $0}' input_file.txt


but i am not getting any output.







awk syntax quotes nawk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Cyrus

44.1k43375




44.1k43375










asked 2 days ago









ramki_ramakrishnan

41117




41117








  • 2




    With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
    – Cyrus
    2 days ago
















  • 2




    With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
    – Cyrus
    2 days ago










2




2




With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
– Cyrus
2 days ago






With a regex: awk '/^1.*C$/' file or awk '/^1,.*,C$/' file
– Cyrus
2 days ago














2 Answers
2






active

oldest

votes

















up vote
3
down vote













Use double quotes:



awk -F, '$1=="1" && $31=="C"{print $0}' file


or



awk -F, '$1=="1" && $31=="C"' file 





share|improve this answer





















  • Note that 1 doesn't require quotes.
    – karakfa
    2 days ago


















up vote
1
down vote













As other users suggested, this can be done using a simple regex. So you can use sed as well as awk



sed '/^1,.*,C$/!d' file





share|improve this answer



















  • 1




    If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
    – karakfa
    2 days ago










  • @karakfa updated, thanks!
    – oguzismail
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184039%2fawk-condition-for-30th-column-of-a-line-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest
































2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













Use double quotes:



awk -F, '$1=="1" && $31=="C"{print $0}' file


or



awk -F, '$1=="1" && $31=="C"' file 





share|improve this answer





















  • Note that 1 doesn't require quotes.
    – karakfa
    2 days ago















up vote
3
down vote













Use double quotes:



awk -F, '$1=="1" && $31=="C"{print $0}' file


or



awk -F, '$1=="1" && $31=="C"' file 





share|improve this answer





















  • Note that 1 doesn't require quotes.
    – karakfa
    2 days ago













up vote
3
down vote










up vote
3
down vote









Use double quotes:



awk -F, '$1=="1" && $31=="C"{print $0}' file


or



awk -F, '$1=="1" && $31=="C"' file 





share|improve this answer












Use double quotes:



awk -F, '$1=="1" && $31=="C"{print $0}' file


or



awk -F, '$1=="1" && $31=="C"' file 






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Cyrus

44.1k43375




44.1k43375












  • Note that 1 doesn't require quotes.
    – karakfa
    2 days ago


















  • Note that 1 doesn't require quotes.
    – karakfa
    2 days ago
















Note that 1 doesn't require quotes.
– karakfa
2 days ago




Note that 1 doesn't require quotes.
– karakfa
2 days ago












up vote
1
down vote













As other users suggested, this can be done using a simple regex. So you can use sed as well as awk



sed '/^1,.*,C$/!d' file





share|improve this answer



















  • 1




    If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
    – karakfa
    2 days ago










  • @karakfa updated, thanks!
    – oguzismail
    2 days ago















up vote
1
down vote













As other users suggested, this can be done using a simple regex. So you can use sed as well as awk



sed '/^1,.*,C$/!d' file





share|improve this answer



















  • 1




    If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
    – karakfa
    2 days ago










  • @karakfa updated, thanks!
    – oguzismail
    2 days ago













up vote
1
down vote










up vote
1
down vote









As other users suggested, this can be done using a simple regex. So you can use sed as well as awk



sed '/^1,.*,C$/!d' file





share|improve this answer














As other users suggested, this can be done using a simple regex. So you can use sed as well as awk



sed '/^1,.*,C$/!d' file






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









oguzismail

1,739516




1,739516








  • 1




    If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
    – karakfa
    2 days ago










  • @karakfa updated, thanks!
    – oguzismail
    2 days ago














  • 1




    If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
    – karakfa
    2 days ago










  • @karakfa updated, thanks!
    – oguzismail
    2 days ago








1




1




If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
– karakfa
2 days ago




If you don't add the delimiters there will be false matches. For example. 11,....,NotC will match as well. /^1,.*,C$/!d should fix this.
– karakfa
2 days ago












@karakfa updated, thanks!
– oguzismail
2 days ago




@karakfa updated, thanks!
– oguzismail
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184039%2fawk-condition-for-30th-column-of-a-line-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

横浜市

Rostock

Europa