want to subtract 2nd column from 1st column if 7th column value is 12019 Community Moderator ElectionHow to multiply a data file with another index data file?Help to read a flat file into unix and output to simplified csv like format for import into excelHow to select rows from a CSV file based on different column values?How to convert several tiff images into xyz coordinates in a single text file using the terminal?Select rows in one file based on specific values in the second fileTo aggregate lines on a filePrint value of 2nd pattern if 1st pattern matches usernameFixing a .csv file where some rows have missing columnsHow to delete the first value and trailing comma from the 7th column in a csv filePerl - working with hashes and arrays for CSV processing

Set and print content of environment variable in cmd.exe subshell?

What are some noteworthy "mic-drop" moments in math?

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

Single word request: Harming the benefactor

Leftbar without indentation

Making a sword in the stone, in a medieval world without magic

Grey hair or white hair

How strictly should I take "Candidates must be local"?

How do you like my writing?

Why would one plane in this picture not have gear down yet?

How did the power source of Mar-Vell's aircraft end up with her?

Can I withdraw from one conference and attend another one with the same abstract?

What wound would be of little consequence to a biped but terrible for a quadruped?

Do f-stop and exposure time perfectly cancel?

Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?

PTIJ: wiping amalek’s memory?

Why is there a voltage between the mains ground and my radiator?

Reverse string, can I make it faster?

How to pass a string to a command that expects a file?

Do items de-spawn in Diablo?

How did Alan Turing break the enigma code using the hint given by the lady in the bar?

Should QA ask requirements to developers?

infinitive telling the purpose

How to to redirect a form to a certain node for anonymous users?



want to subtract 2nd column from 1st column if 7th column value is 1



2019 Community Moderator ElectionHow to multiply a data file with another index data file?Help to read a flat file into unix and output to simplified csv like format for import into excelHow to select rows from a CSV file based on different column values?How to convert several tiff images into xyz coordinates in a single text file using the terminal?Select rows in one file based on specific values in the second fileTo aggregate lines on a filePrint value of 2nd pattern if 1st pattern matches usernameFixing a .csv file where some rows have missing columnsHow to delete the first value and trailing comma from the 7th column in a csv filePerl - working with hashes and arrays for CSV processing










0















I have files having header values on top with extension .txt. I want to subtract 2nd column from 1st column if 7th column value is 1. Ignore those rows having value other than 1 on 7th column.



File sample is here below:



"Header of file of Munir1 in text file"
1,9021,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9022,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9023,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,1,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,2,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,3,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,4,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,5,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;









share|improve this question









New contributor




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















  • 1





    Please edit your post and append what have you been trying so far.

    – Juan
    1 hour ago















0















I have files having header values on top with extension .txt. I want to subtract 2nd column from 1st column if 7th column value is 1. Ignore those rows having value other than 1 on 7th column.



File sample is here below:



"Header of file of Munir1 in text file"
1,9021,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9022,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9023,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,1,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,2,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,3,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,4,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,5,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;









share|improve this question









New contributor




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















  • 1





    Please edit your post and append what have you been trying so far.

    – Juan
    1 hour ago













0












0








0


1






I have files having header values on top with extension .txt. I want to subtract 2nd column from 1st column if 7th column value is 1. Ignore those rows having value other than 1 on 7th column.



File sample is here below:



"Header of file of Munir1 in text file"
1,9021,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9022,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9023,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,1,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,2,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,3,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,4,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,5,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;









share|improve this question









New contributor




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












I have files having header values on top with extension .txt. I want to subtract 2nd column from 1st column if 7th column value is 1. Ignore those rows having value other than 1 on 7th column.



File sample is here below:



"Header of file of Munir1 in text file"
1,9021,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9022,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,9023,"Munir1",,,,5,"/prestack/BG-SUL-1995/Munir1",1,;
1,1,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,2,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,3,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,4,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;
1,5,"Munir1",0,,,1,"/prestack/BG-SUL-1995/Munir1",1,;






linux csv






share|improve this question









New contributor




aani 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




aani 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








edited 45 mins ago









Samuel P.

1287




1287






New contributor




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









asked 1 hour ago









aaniaani

1




1




New contributor




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





New contributor





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






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







  • 1





    Please edit your post and append what have you been trying so far.

    – Juan
    1 hour ago












  • 1





    Please edit your post and append what have you been trying so far.

    – Juan
    1 hour ago







1




1





Please edit your post and append what have you been trying so far.

– Juan
1 hour ago





Please edit your post and append what have you been trying so far.

– Juan
1 hour ago










1 Answer
1






active

oldest

votes


















0














You can print the result on this way:



awk -F, '$7==1 print $1-$2' input_file.txt


If you want to subtract 1st field in place you can use code like this:



awk -F, -v OFS=, '$7==1 $1-=$2 ; print $0' input_file.txt


If you want to print all the lines (including notchanged) you can use code like this:



awk -F, -v OFS=, '$7==1 $1-=$2 1' input_file.txt





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',
    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
    );



    );






    aani 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%2f505870%2fwant-to-subtract-2nd-column-from-1st-column-if-7th-column-value-is-1%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









    0














    You can print the result on this way:



    awk -F, '$7==1 print $1-$2' input_file.txt


    If you want to subtract 1st field in place you can use code like this:



    awk -F, -v OFS=, '$7==1 $1-=$2 ; print $0' input_file.txt


    If you want to print all the lines (including notchanged) you can use code like this:



    awk -F, -v OFS=, '$7==1 $1-=$2 1' input_file.txt





    share|improve this answer





























      0














      You can print the result on this way:



      awk -F, '$7==1 print $1-$2' input_file.txt


      If you want to subtract 1st field in place you can use code like this:



      awk -F, -v OFS=, '$7==1 $1-=$2 ; print $0' input_file.txt


      If you want to print all the lines (including notchanged) you can use code like this:



      awk -F, -v OFS=, '$7==1 $1-=$2 1' input_file.txt





      share|improve this answer



























        0












        0








        0







        You can print the result on this way:



        awk -F, '$7==1 print $1-$2' input_file.txt


        If you want to subtract 1st field in place you can use code like this:



        awk -F, -v OFS=, '$7==1 $1-=$2 ; print $0' input_file.txt


        If you want to print all the lines (including notchanged) you can use code like this:



        awk -F, -v OFS=, '$7==1 $1-=$2 1' input_file.txt





        share|improve this answer















        You can print the result on this way:



        awk -F, '$7==1 print $1-$2' input_file.txt


        If you want to subtract 1st field in place you can use code like this:



        awk -F, -v OFS=, '$7==1 $1-=$2 ; print $0' input_file.txt


        If you want to print all the lines (including notchanged) you can use code like this:



        awk -F, -v OFS=, '$7==1 $1-=$2 1' input_file.txt






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 25 mins ago

























        answered 42 mins ago









        Romeo NinovRomeo Ninov

        6,58632029




        6,58632029




















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









            draft saved

            draft discarded


















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












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











            aani 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%2f505870%2fwant-to-subtract-2nd-column-from-1st-column-if-7th-column-value-is-1%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







            -csv, linux

            Popular posts from this blog

            Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

            What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?

            Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?