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
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
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.
add a comment |
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
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
add a comment |
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
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
linux csv
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.
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited 25 mins ago
answered 42 mins ago
Romeo NinovRomeo Ninov
6,58632029
6,58632029
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Please edit your post and append what have you been trying so far.
– Juan
1 hour ago