Remove words from a column in a fileone column from output column on awkHow to Keep Text Consistent in A Shell ScriptStoring some strings in a arraySimple BASH - how to read file line by lineextract the oldest values from a master file per each codebash shell script, searching for complex line in makefile (shell parameter expansion issue)compare two lines and print unmatched words from two filesAdd or append new column to csv file using shell script

C - random password generator

What is a logic gate?

How did the Druids learn the Greek language by the time of Caesar's campaign in Gaul?

Removing moon "rays" - beginner

Why do we use cross products in physics?

Is the speed of light in all media independent of reference frame?

What specifically can swap do that RAM can't

How to say No to idea given by team member, when I know from my experience that it is going to fail?

What's the difference between xxxx-client and xxxx-server packages?

Is there mention of Maitreya Buddha in Pali Canon?

Students using the same flawed online solution sheet as the grading TA

How to teach children Santa is not real, while respecting other kids beliefs?

Can you marry a girl in Stardew Valley if you are a girl?

What are the downsides of being a debt-free country (no national debt?

Why is "runway behind you" useless?

Biggest Irreducible Hello World

Is Nessa or Vanessa a Catholic name?

Aligning equations with unequal amount of elements

Do any countries have a pensions system funded entirely by past contributions, rather than current taxes?

Is it safe to drink the water from the fountains found all over the older parts of Rome?

When was Newton "not good enough" for spaceflight; first use and first absolute requirement for relativistic corrections?

Reference Request: Where can I read about philosophy of the digital arts?

I have to make an API where I can return orders (product name) placed by a customer using customer Id?

Reverse Polish Notation (RPN) Calculator



Remove words from a column in a file


one column from output column on awkHow to Keep Text Consistent in A Shell ScriptStoring some strings in a arraySimple BASH - how to read file line by lineextract the oldest values from a master file per each codebash shell script, searching for complex line in makefile (shell parameter expansion issue)compare two lines and print unmatched words from two filesAdd or append new column to csv file using shell script






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









2


















I have file which contains something like below



5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26T16:54:25Z,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26T16:52:59Z,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26T16:46:52Z,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I want to trim the 3rd column 2019-09-27T11:06:23Z to 2019-09-27
Basically I want to remove time and just keep date here.



4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I tried using awk with gsub
awk 'gsub("T","",$3);print' test



But no luck, please help how can I achieve this.










share|improve this question

























  • sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

    – bac0n
    Sep 30 at 8:04











  • @bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

    – harsha
    Sep 30 at 8:19











  • just remove 'g'

    – bac0n
    Sep 30 at 9:09

















2


















I have file which contains something like below



5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26T16:54:25Z,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26T16:52:59Z,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26T16:46:52Z,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I want to trim the 3rd column 2019-09-27T11:06:23Z to 2019-09-27
Basically I want to remove time and just keep date here.



4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I tried using awk with gsub
awk 'gsub("T","",$3);print' test



But no luck, please help how can I achieve this.










share|improve this question

























  • sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

    – bac0n
    Sep 30 at 8:04











  • @bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

    – harsha
    Sep 30 at 8:19











  • just remove 'g'

    – bac0n
    Sep 30 at 9:09













2













2









2








I have file which contains something like below



5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26T16:54:25Z,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26T16:52:59Z,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26T16:46:52Z,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I want to trim the 3rd column 2019-09-27T11:06:23Z to 2019-09-27
Basically I want to remove time and just keep date here.



4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I tried using awk with gsub
awk 'gsub("T","",$3);print' test



But no luck, please help how can I achieve this.










share|improve this question














I have file which contains something like below



5,test,2019-09-27T11:06:23Z,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26T16:56:40Z,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26T16:54:25Z,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26T16:52:59Z,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26T16:46:52Z,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I want to trim the 3rd column 2019-09-27T11:06:23Z to 2019-09-27
Basically I want to remove time and just keep date here.



4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


I tried using awk with gsub
awk 'gsub("T","",$3);print' test



But no luck, please help how can I achieve this.







command-line bash scripts awk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 30 at 6:47









harshaharsha

18313 bronze badges




18313 bronze badges















  • sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

    – bac0n
    Sep 30 at 8:04











  • @bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

    – harsha
    Sep 30 at 8:19











  • just remove 'g'

    – bac0n
    Sep 30 at 9:09

















  • sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

    – bac0n
    Sep 30 at 8:04











  • @bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

    – harsha
    Sep 30 at 8:19











  • just remove 'g'

    – bac0n
    Sep 30 at 9:09
















sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

– bac0n
Sep 30 at 8:04





sed -E 's/T([0-9]+:)+[0-9]+Z//g' file

– bac0n
Sep 30 at 8:04













@bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

– harsha
Sep 30 at 8:19





@bac0n This try to find all the columns to that particular pattern, I want this to be replaced only in 3rd column.

– harsha
Sep 30 at 8:19













just remove 'g'

– bac0n
Sep 30 at 9:09





just remove 'g'

– bac0n
Sep 30 at 9:09










1 Answer
1






active

oldest

votes


















4



















Try:



$ awk -F, 'sub(/T.*/,"",$3);print' OFS=, file
5,test,2019-09-27,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


Notes:



  1. Your file is comma separated. Thus, you need to specify -F, so that, on input, each line is divided into fields based on commas.


  2. Since you want a comma-separated file on output, we also need to specify OFS=,.


  3. The first argument to sub (or gsub) should be a regular expression not a string. In our case the regular expression should match T and everything after. .* means everything after.



  4. Since awk programmers often pride themselves on conciseness, you might want to remove print (too long-winded) and instead use:



    awk -F, 'sub(/T.*/,"",$3) 1' OFS=, file






share|improve this answer


























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: 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/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
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1177595%2fremove-words-from-a-column-in-a-file%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









    4



















    Try:



    $ awk -F, 'sub(/T.*/,"",$3);print' OFS=, file
    5,test,2019-09-27,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
    4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
    3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
    2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
    1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


    Notes:



    1. Your file is comma separated. Thus, you need to specify -F, so that, on input, each line is divided into fields based on commas.


    2. Since you want a comma-separated file on output, we also need to specify OFS=,.


    3. The first argument to sub (or gsub) should be a regular expression not a string. In our case the regular expression should match T and everything after. .* means everything after.



    4. Since awk programmers often pride themselves on conciseness, you might want to remove print (too long-winded) and instead use:



      awk -F, 'sub(/T.*/,"",$3) 1' OFS=, file






    share|improve this answer





























      4



















      Try:



      $ awk -F, 'sub(/T.*/,"",$3);print' OFS=, file
      5,test,2019-09-27,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
      4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
      3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
      2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
      1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


      Notes:



      1. Your file is comma separated. Thus, you need to specify -F, so that, on input, each line is divided into fields based on commas.


      2. Since you want a comma-separated file on output, we also need to specify OFS=,.


      3. The first argument to sub (or gsub) should be a regular expression not a string. In our case the regular expression should match T and everything after. .* means everything after.



      4. Since awk programmers often pride themselves on conciseness, you might want to remove print (too long-winded) and instead use:



        awk -F, 'sub(/T.*/,"",$3) 1' OFS=, file






      share|improve this answer



























        4















        4











        4









        Try:



        $ awk -F, 'sub(/T.*/,"",$3);print' OFS=, file
        5,test,2019-09-27,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
        4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
        3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
        2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
        1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


        Notes:



        1. Your file is comma separated. Thus, you need to specify -F, so that, on input, each line is divided into fields based on commas.


        2. Since you want a comma-separated file on output, we also need to specify OFS=,.


        3. The first argument to sub (or gsub) should be a regular expression not a string. In our case the regular expression should match T and everything after. .* means everything after.



        4. Since awk programmers often pride themselves on conciseness, you might want to remove print (too long-winded) and instead use:



          awk -F, 'sub(/T.*/,"",$3) 1' OFS=, file






        share|improve this answer














        Try:



        $ awk -F, 'sub(/T.*/,"",$3);print' OFS=, file
        5,test,2019-09-27,closed,harshavardhanc,2019-09-27T11:09:28Z,2,2
        4,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:57:02Z,1,1
        3,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:54:55Z,1,1
        2,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:55:19Z,1,1
        1,test,2019-09-26,closed,harshavardhanc,2019-09-26T16:47:25Z,1,1


        Notes:



        1. Your file is comma separated. Thus, you need to specify -F, so that, on input, each line is divided into fields based on commas.


        2. Since you want a comma-separated file on output, we also need to specify OFS=,.


        3. The first argument to sub (or gsub) should be a regular expression not a string. In our case the regular expression should match T and everything after. .* means everything after.



        4. Since awk programmers often pride themselves on conciseness, you might want to remove print (too long-winded) and instead use:



          awk -F, 'sub(/T.*/,"",$3) 1' OFS=, file







        share|improve this answer













        share|improve this answer




        share|improve this answer










        answered Sep 30 at 7:13









        John1024John1024

        11.1k30 silver badges40 bronze badges




        11.1k30 silver badges40 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1177595%2fremove-words-from-a-column-in-a-file%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

            Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

            Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?

            apt-get update fails to fetch files, “Temporary failure resolving …” errorWhy does apt-get fail to resolve the mirror?Apt-get update not working in Ubuntu 16.04 “temporary failure resolving”Ubuntu 16.04 Server updates - Temporary failure resolving 'ro.archive.ubuntu.com'“Failed to fetch… Temporary failure resolving…” when trying to installTemporary failure resolving ca.archive.ubuntu.comUbuntu 18.04 sudo apt update doesn't work (Failed to Fetch)apt-get error: “Temporary failure resolving 'archive.ubuntu.com' ”“Temporary failure resolving us.archive.ubuntu.com” Live USB rescueTemporary failure resolving 'es.archive.ubuntu.com' on Ubuntu Server15.04 Server fails to update with failed to fetch temporary failure resolving errorsCan't install software from Software CenterApt-get failed to fetch from Ubuntu server with error code 404“Unable to connect” error with apt-get: possible proxy?v12.10 can't apt-get update111: Connection refused when trying apt updateSudo apt-get update