Change a list of strings to lowercase

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have two files, one file contains a list of strings.



+stringa +Dog +Cat
+cat +Tux +elephant


and the second file (csv) contains something like:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +Tux +elephant","Other something"
"34524 xyz","+stringa +Dog +Cat","third something"


the result should be:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"


How I can change the strings, that match my list of patterns, to lowercase?



My comma-separated values file have about 30 columns and about 1500 rows.







share|improve this question


















  • 1




    can you add some code you tried? what tools do you have? GNU sed? perl? awk?
    – Sundeep
    Nov 27 '17 at 10:34










  • Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
    – Jeff Schaller
    Nov 27 '17 at 10:48










  • @Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
    – FaxMax
    Nov 27 '17 at 10:54














up vote
2
down vote

favorite












I have two files, one file contains a list of strings.



+stringa +Dog +Cat
+cat +Tux +elephant


and the second file (csv) contains something like:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +Tux +elephant","Other something"
"34524 xyz","+stringa +Dog +Cat","third something"


the result should be:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"


How I can change the strings, that match my list of patterns, to lowercase?



My comma-separated values file have about 30 columns and about 1500 rows.







share|improve this question


















  • 1




    can you add some code you tried? what tools do you have? GNU sed? perl? awk?
    – Sundeep
    Nov 27 '17 at 10:34










  • Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
    – Jeff Schaller
    Nov 27 '17 at 10:48










  • @Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
    – FaxMax
    Nov 27 '17 at 10:54












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have two files, one file contains a list of strings.



+stringa +Dog +Cat
+cat +Tux +elephant


and the second file (csv) contains something like:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +Tux +elephant","Other something"
"34524 xyz","+stringa +Dog +Cat","third something"


the result should be:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"


How I can change the strings, that match my list of patterns, to lowercase?



My comma-separated values file have about 30 columns and about 1500 rows.







share|improve this question














I have two files, one file contains a list of strings.



+stringa +Dog +Cat
+cat +Tux +elephant


and the second file (csv) contains something like:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +Tux +elephant","Other something"
"34524 xyz","+stringa +Dog +Cat","third something"


the result should be:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"


How I can change the strings, that match my list of patterns, to lowercase?



My comma-separated values file have about 30 columns and about 1500 rows.









share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '17 at 14:44









Philip Kirkbride

2,2922470




2,2922470










asked Nov 27 '17 at 10:24









FaxMax

428219




428219







  • 1




    can you add some code you tried? what tools do you have? GNU sed? perl? awk?
    – Sundeep
    Nov 27 '17 at 10:34










  • Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
    – Jeff Schaller
    Nov 27 '17 at 10:48










  • @Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
    – FaxMax
    Nov 27 '17 at 10:54












  • 1




    can you add some code you tried? what tools do you have? GNU sed? perl? awk?
    – Sundeep
    Nov 27 '17 at 10:34










  • Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
    – Jeff Schaller
    Nov 27 '17 at 10:48










  • @Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
    – FaxMax
    Nov 27 '17 at 10:54







1




1




can you add some code you tried? what tools do you have? GNU sed? perl? awk?
– Sundeep
Nov 27 '17 at 10:34




can you add some code you tried? what tools do you have? GNU sed? perl? awk?
– Sundeep
Nov 27 '17 at 10:34












Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
– Jeff Schaller
Nov 27 '17 at 10:48




Despite newer versions having an upper- & lower-case variable operator, bash is not a text editor.
– Jeff Schaller
Nov 27 '17 at 10:48












@Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
– FaxMax
Nov 27 '17 at 10:54




@Sundeep I can not find the right approach. I do not understand perl but it is available. I use Debian 8.9 (Jessie). The point is i like change only the pattern, not the whole file. I have sed, awk, tr
– FaxMax
Nov 27 '17 at 10:54










3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










With GNU sed, assumes that you do not have any meta character in list of strings, + is not a meta character with default BRE





$ # create substitute command for each line
$ sed 's/.*/s|"&"|\L&|gi/' f1
s|"+stringa +Dog +Cat"|L&|gi
s|"+cat +Tux +elephant"|L&|gi

$ # pass those commands as sed script
$ sed -f <(sed 's/.*/s|"&"|\L&|gi/' f1) ip.csv
"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"

$ # or save them in a file and use
$ sed 's/.*/s|"&"|\L&|gi/' f1 > f2
$ sed -f f2 ip.csv



  • L to convert string to lowercase


  • g for replacing all occurrences in a line, i for case-insensitive matching



If you don't have GNU sed



$ # Q to quote metacharacters
$ # but will have issues if you have or $ or @
$ sed 's/.*/s|\Q"&"|\L$&|gi;/' f1
s|Q"+stringa +Dog +Cat"|L$&|gi;
s|Q"+cat +Tux +elephant"|L$&|gi;

$ perl -p <(sed 's/.*/s|\Q"&"|\L$&|gi;/' f1) ip.csv
"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"




As noted by Stéphane Chazelas, this could lead to code injection vulnerabilities if contents of f1 is not under control






share|improve this answer


















  • 1




    It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
    – Stéphane Chazelas
    Nov 27 '17 at 11:23










  • good observation as always :) added a note
    – Sundeep
    Nov 27 '17 at 11:31

















up vote
2
down vote













With perl, assuming you want each word in the first file to be turned to lowercase:



perl -pe '
BEGIN local $/ = undef; $regex = join "
s/$regex/L$&/g' file1.words file2.csv


local $/ = undef makes the record separator for the BEGIN block undefined so that the one invocation of <> there, slurps the whole first file (file1.words) in. We split that on whitespace (split " " is special in perl in the same way as awk -F " " is in awk), and join the resulting words with | after having regex-quoted them and made them case insensitive.



So we have a huge regexp that is something like (?i:word1)|(?i:word2)|... which we apply on each line of the second file in the rest of the code.



If it's each string in each line of the first file, then that can be simplified to:



perl -pe '
BEGIN ", map qrQ$_Ei, @strings
s/$regex/L$&/g' < file1.strings file2.csv


There, we open the first file on stdin instead of passing it as argument. <STDIN> returns a list of its lines from which we remove the delimiters with chomp, and join with | as above.



If you don't want it to be limited to ASCII characters, add the -Mopen=locale option.






share|improve this answer


















  • 1




    @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
    – Stéphane Chazelas
    Nov 27 '17 at 11:45

















up vote
2
down vote













AWK solution (for your current input):



Assuming that the 2nd field is of main interest and values in search file are double-quoted.



awk 'NR==FNR $0="42"$0"42"; a[$0]; next 
$2 in a $2=tolower($2) 1' patterns FS=',' OFS=',' file.csv


  • $0="42"$0"42" - wrap a pattern line with double quotes while iterating through the lines of patterns file


  • a[$0] - capturing a pattern line into array a


  • $2 in a $2=tolower($2) - if the 2nd field value from line of file.csv file is in the list of patterns(i.e. array a) - convert all characters in it to lowercase $2=tolower($2)



The output:



"123456 Abc","+Stringx +123","something"
"23456 dEf","+cat +tux +elephant","Other something"
"34524 xyz","+stringa +dog +cat","third something"





share|improve this answer






















    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407252%2fchange-a-list-of-strings-to-lowercase%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    With GNU sed, assumes that you do not have any meta character in list of strings, + is not a meta character with default BRE





    $ # create substitute command for each line
    $ sed 's/.*/s|"&"|\L&|gi/' f1
    s|"+stringa +Dog +Cat"|L&|gi
    s|"+cat +Tux +elephant"|L&|gi

    $ # pass those commands as sed script
    $ sed -f <(sed 's/.*/s|"&"|\L&|gi/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"

    $ # or save them in a file and use
    $ sed 's/.*/s|"&"|\L&|gi/' f1 > f2
    $ sed -f f2 ip.csv



    • L to convert string to lowercase


    • g for replacing all occurrences in a line, i for case-insensitive matching



    If you don't have GNU sed



    $ # Q to quote metacharacters
    $ # but will have issues if you have or $ or @
    $ sed 's/.*/s|\Q"&"|\L$&|gi;/' f1
    s|Q"+stringa +Dog +Cat"|L$&|gi;
    s|Q"+cat +Tux +elephant"|L$&|gi;

    $ perl -p <(sed 's/.*/s|\Q"&"|\L$&|gi;/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"




    As noted by Stéphane Chazelas, this could lead to code injection vulnerabilities if contents of f1 is not under control






    share|improve this answer


















    • 1




      It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
      – Stéphane Chazelas
      Nov 27 '17 at 11:23










    • good observation as always :) added a note
      – Sundeep
      Nov 27 '17 at 11:31














    up vote
    3
    down vote



    accepted










    With GNU sed, assumes that you do not have any meta character in list of strings, + is not a meta character with default BRE





    $ # create substitute command for each line
    $ sed 's/.*/s|"&"|\L&|gi/' f1
    s|"+stringa +Dog +Cat"|L&|gi
    s|"+cat +Tux +elephant"|L&|gi

    $ # pass those commands as sed script
    $ sed -f <(sed 's/.*/s|"&"|\L&|gi/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"

    $ # or save them in a file and use
    $ sed 's/.*/s|"&"|\L&|gi/' f1 > f2
    $ sed -f f2 ip.csv



    • L to convert string to lowercase


    • g for replacing all occurrences in a line, i for case-insensitive matching



    If you don't have GNU sed



    $ # Q to quote metacharacters
    $ # but will have issues if you have or $ or @
    $ sed 's/.*/s|\Q"&"|\L$&|gi;/' f1
    s|Q"+stringa +Dog +Cat"|L$&|gi;
    s|Q"+cat +Tux +elephant"|L$&|gi;

    $ perl -p <(sed 's/.*/s|\Q"&"|\L$&|gi;/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"




    As noted by Stéphane Chazelas, this could lead to code injection vulnerabilities if contents of f1 is not under control






    share|improve this answer


















    • 1




      It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
      – Stéphane Chazelas
      Nov 27 '17 at 11:23










    • good observation as always :) added a note
      – Sundeep
      Nov 27 '17 at 11:31












    up vote
    3
    down vote



    accepted







    up vote
    3
    down vote



    accepted






    With GNU sed, assumes that you do not have any meta character in list of strings, + is not a meta character with default BRE





    $ # create substitute command for each line
    $ sed 's/.*/s|"&"|\L&|gi/' f1
    s|"+stringa +Dog +Cat"|L&|gi
    s|"+cat +Tux +elephant"|L&|gi

    $ # pass those commands as sed script
    $ sed -f <(sed 's/.*/s|"&"|\L&|gi/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"

    $ # or save them in a file and use
    $ sed 's/.*/s|"&"|\L&|gi/' f1 > f2
    $ sed -f f2 ip.csv



    • L to convert string to lowercase


    • g for replacing all occurrences in a line, i for case-insensitive matching



    If you don't have GNU sed



    $ # Q to quote metacharacters
    $ # but will have issues if you have or $ or @
    $ sed 's/.*/s|\Q"&"|\L$&|gi;/' f1
    s|Q"+stringa +Dog +Cat"|L$&|gi;
    s|Q"+cat +Tux +elephant"|L$&|gi;

    $ perl -p <(sed 's/.*/s|\Q"&"|\L$&|gi;/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"




    As noted by Stéphane Chazelas, this could lead to code injection vulnerabilities if contents of f1 is not under control






    share|improve this answer














    With GNU sed, assumes that you do not have any meta character in list of strings, + is not a meta character with default BRE





    $ # create substitute command for each line
    $ sed 's/.*/s|"&"|\L&|gi/' f1
    s|"+stringa +Dog +Cat"|L&|gi
    s|"+cat +Tux +elephant"|L&|gi

    $ # pass those commands as sed script
    $ sed -f <(sed 's/.*/s|"&"|\L&|gi/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"

    $ # or save them in a file and use
    $ sed 's/.*/s|"&"|\L&|gi/' f1 > f2
    $ sed -f f2 ip.csv



    • L to convert string to lowercase


    • g for replacing all occurrences in a line, i for case-insensitive matching



    If you don't have GNU sed



    $ # Q to quote metacharacters
    $ # but will have issues if you have or $ or @
    $ sed 's/.*/s|\Q"&"|\L$&|gi;/' f1
    s|Q"+stringa +Dog +Cat"|L$&|gi;
    s|Q"+cat +Tux +elephant"|L$&|gi;

    $ perl -p <(sed 's/.*/s|\Q"&"|\L$&|gi;/' f1) ip.csv
    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"




    As noted by Stéphane Chazelas, this could lead to code injection vulnerabilities if contents of f1 is not under control







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 28 '17 at 10:27

























    answered Nov 27 '17 at 11:02









    Sundeep

    6,9611826




    6,9611826







    • 1




      It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
      – Stéphane Chazelas
      Nov 27 '17 at 11:23










    • good observation as always :) added a note
      – Sundeep
      Nov 27 '17 at 11:31












    • 1




      It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
      – Stéphane Chazelas
      Nov 27 '17 at 11:23










    • good observation as always :) added a note
      – Sundeep
      Nov 27 '17 at 11:31







    1




    1




    It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
    – Stéphane Chazelas
    Nov 27 '17 at 11:23




    It may be worth noting that those amount to command injection vulnerabilities if the content of f1 is not under your control.
    – Stéphane Chazelas
    Nov 27 '17 at 11:23












    good observation as always :) added a note
    – Sundeep
    Nov 27 '17 at 11:31




    good observation as always :) added a note
    – Sundeep
    Nov 27 '17 at 11:31












    up vote
    2
    down vote













    With perl, assuming you want each word in the first file to be turned to lowercase:



    perl -pe '
    BEGIN local $/ = undef; $regex = join "
    s/$regex/L$&/g' file1.words file2.csv


    local $/ = undef makes the record separator for the BEGIN block undefined so that the one invocation of <> there, slurps the whole first file (file1.words) in. We split that on whitespace (split " " is special in perl in the same way as awk -F " " is in awk), and join the resulting words with | after having regex-quoted them and made them case insensitive.



    So we have a huge regexp that is something like (?i:word1)|(?i:word2)|... which we apply on each line of the second file in the rest of the code.



    If it's each string in each line of the first file, then that can be simplified to:



    perl -pe '
    BEGIN ", map qrQ$_Ei, @strings
    s/$regex/L$&/g' < file1.strings file2.csv


    There, we open the first file on stdin instead of passing it as argument. <STDIN> returns a list of its lines from which we remove the delimiters with chomp, and join with | as above.



    If you don't want it to be limited to ASCII characters, add the -Mopen=locale option.






    share|improve this answer


















    • 1




      @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
      – Stéphane Chazelas
      Nov 27 '17 at 11:45














    up vote
    2
    down vote













    With perl, assuming you want each word in the first file to be turned to lowercase:



    perl -pe '
    BEGIN local $/ = undef; $regex = join "
    s/$regex/L$&/g' file1.words file2.csv


    local $/ = undef makes the record separator for the BEGIN block undefined so that the one invocation of <> there, slurps the whole first file (file1.words) in. We split that on whitespace (split " " is special in perl in the same way as awk -F " " is in awk), and join the resulting words with | after having regex-quoted them and made them case insensitive.



    So we have a huge regexp that is something like (?i:word1)|(?i:word2)|... which we apply on each line of the second file in the rest of the code.



    If it's each string in each line of the first file, then that can be simplified to:



    perl -pe '
    BEGIN ", map qrQ$_Ei, @strings
    s/$regex/L$&/g' < file1.strings file2.csv


    There, we open the first file on stdin instead of passing it as argument. <STDIN> returns a list of its lines from which we remove the delimiters with chomp, and join with | as above.



    If you don't want it to be limited to ASCII characters, add the -Mopen=locale option.






    share|improve this answer


















    • 1




      @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
      – Stéphane Chazelas
      Nov 27 '17 at 11:45












    up vote
    2
    down vote










    up vote
    2
    down vote









    With perl, assuming you want each word in the first file to be turned to lowercase:



    perl -pe '
    BEGIN local $/ = undef; $regex = join "
    s/$regex/L$&/g' file1.words file2.csv


    local $/ = undef makes the record separator for the BEGIN block undefined so that the one invocation of <> there, slurps the whole first file (file1.words) in. We split that on whitespace (split " " is special in perl in the same way as awk -F " " is in awk), and join the resulting words with | after having regex-quoted them and made them case insensitive.



    So we have a huge regexp that is something like (?i:word1)|(?i:word2)|... which we apply on each line of the second file in the rest of the code.



    If it's each string in each line of the first file, then that can be simplified to:



    perl -pe '
    BEGIN ", map qrQ$_Ei, @strings
    s/$regex/L$&/g' < file1.strings file2.csv


    There, we open the first file on stdin instead of passing it as argument. <STDIN> returns a list of its lines from which we remove the delimiters with chomp, and join with | as above.



    If you don't want it to be limited to ASCII characters, add the -Mopen=locale option.






    share|improve this answer














    With perl, assuming you want each word in the first file to be turned to lowercase:



    perl -pe '
    BEGIN local $/ = undef; $regex = join "
    s/$regex/L$&/g' file1.words file2.csv


    local $/ = undef makes the record separator for the BEGIN block undefined so that the one invocation of <> there, slurps the whole first file (file1.words) in. We split that on whitespace (split " " is special in perl in the same way as awk -F " " is in awk), and join the resulting words with | after having regex-quoted them and made them case insensitive.



    So we have a huge regexp that is something like (?i:word1)|(?i:word2)|... which we apply on each line of the second file in the rest of the code.



    If it's each string in each line of the first file, then that can be simplified to:



    perl -pe '
    BEGIN ", map qrQ$_Ei, @strings
    s/$regex/L$&/g' < file1.strings file2.csv


    There, we open the first file on stdin instead of passing it as argument. <STDIN> returns a list of its lines from which we remove the delimiters with chomp, and join with | as above.



    If you don't want it to be limited to ASCII characters, add the -Mopen=locale option.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 27 '17 at 14:07

























    answered Nov 27 '17 at 11:14









    Stéphane Chazelas

    282k53521854




    282k53521854







    • 1




      @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
      – Stéphane Chazelas
      Nov 27 '17 at 11:45












    • 1




      @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
      – Stéphane Chazelas
      Nov 27 '17 at 11:45







    1




    1




    @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
    – Stéphane Chazelas
    Nov 27 '17 at 11:45




    @Sundeep. That was my initial interpretation, but now that you mention it, you're probably right the lines of file1 are probably to be the strings to be matched. See edit.
    – Stéphane Chazelas
    Nov 27 '17 at 11:45










    up vote
    2
    down vote













    AWK solution (for your current input):



    Assuming that the 2nd field is of main interest and values in search file are double-quoted.



    awk 'NR==FNR $0="42"$0"42"; a[$0]; next 
    $2 in a $2=tolower($2) 1' patterns FS=',' OFS=',' file.csv


    • $0="42"$0"42" - wrap a pattern line with double quotes while iterating through the lines of patterns file


    • a[$0] - capturing a pattern line into array a


    • $2 in a $2=tolower($2) - if the 2nd field value from line of file.csv file is in the list of patterns(i.e. array a) - convert all characters in it to lowercase $2=tolower($2)



    The output:



    "123456 Abc","+Stringx +123","something"
    "23456 dEf","+cat +tux +elephant","Other something"
    "34524 xyz","+stringa +dog +cat","third something"





    share|improve this answer


























      up vote
      2
      down vote













      AWK solution (for your current input):



      Assuming that the 2nd field is of main interest and values in search file are double-quoted.



      awk 'NR==FNR $0="42"$0"42"; a[$0]; next 
      $2 in a $2=tolower($2) 1' patterns FS=',' OFS=',' file.csv


      • $0="42"$0"42" - wrap a pattern line with double quotes while iterating through the lines of patterns file


      • a[$0] - capturing a pattern line into array a


      • $2 in a $2=tolower($2) - if the 2nd field value from line of file.csv file is in the list of patterns(i.e. array a) - convert all characters in it to lowercase $2=tolower($2)



      The output:



      "123456 Abc","+Stringx +123","something"
      "23456 dEf","+cat +tux +elephant","Other something"
      "34524 xyz","+stringa +dog +cat","third something"





      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        AWK solution (for your current input):



        Assuming that the 2nd field is of main interest and values in search file are double-quoted.



        awk 'NR==FNR $0="42"$0"42"; a[$0]; next 
        $2 in a $2=tolower($2) 1' patterns FS=',' OFS=',' file.csv


        • $0="42"$0"42" - wrap a pattern line with double quotes while iterating through the lines of patterns file


        • a[$0] - capturing a pattern line into array a


        • $2 in a $2=tolower($2) - if the 2nd field value from line of file.csv file is in the list of patterns(i.e. array a) - convert all characters in it to lowercase $2=tolower($2)



        The output:



        "123456 Abc","+Stringx +123","something"
        "23456 dEf","+cat +tux +elephant","Other something"
        "34524 xyz","+stringa +dog +cat","third something"





        share|improve this answer














        AWK solution (for your current input):



        Assuming that the 2nd field is of main interest and values in search file are double-quoted.



        awk 'NR==FNR $0="42"$0"42"; a[$0]; next 
        $2 in a $2=tolower($2) 1' patterns FS=',' OFS=',' file.csv


        • $0="42"$0"42" - wrap a pattern line with double quotes while iterating through the lines of patterns file


        • a[$0] - capturing a pattern line into array a


        • $2 in a $2=tolower($2) - if the 2nd field value from line of file.csv file is in the list of patterns(i.e. array a) - convert all characters in it to lowercase $2=tolower($2)



        The output:



        "123456 Abc","+Stringx +123","something"
        "23456 dEf","+cat +tux +elephant","Other something"
        "34524 xyz","+stringa +dog +cat","third something"






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 27 '17 at 15:39

























        answered Nov 27 '17 at 10:50









        RomanPerekhrest

        22.4k12145




        22.4k12145



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407252%2fchange-a-list-of-strings-to-lowercase%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay