Creating a file from another file on the basis of a numeric value in each line
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
We will generate a csv file with below values.
yp1234,577,1,3
yp5678,570,3,5
yp9012,132,8,9
I need to extract data and create files based on second column. If it's value greater than 577 then the whole line has to be extracted and placed in a separate file.
I mean I need a file having lines with second column greater than 577.
sed awk
add a comment |
We will generate a csv file with below values.
yp1234,577,1,3
yp5678,570,3,5
yp9012,132,8,9
I need to extract data and create files based on second column. If it's value greater than 577 then the whole line has to be extracted and placed in a separate file.
I mean I need a file having lines with second column greater than 577.
sed awk
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30
add a comment |
We will generate a csv file with below values.
yp1234,577,1,3
yp5678,570,3,5
yp9012,132,8,9
I need to extract data and create files based on second column. If it's value greater than 577 then the whole line has to be extracted and placed in a separate file.
I mean I need a file having lines with second column greater than 577.
sed awk
We will generate a csv file with below values.
yp1234,577,1,3
yp5678,570,3,5
yp9012,132,8,9
I need to extract data and create files based on second column. If it's value greater than 577 then the whole line has to be extracted and placed in a separate file.
I mean I need a file having lines with second column greater than 577.
sed awk
sed awk
edited Mar 9 at 12:16
Rui F Ribeiro
41.9k1483142
41.9k1483142
asked Jun 18 '14 at 22:46
user130240user130240
2112
2112
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30
add a comment |
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30
add a comment |
1 Answer
1
active
oldest
votes
It can be done using the below command.
awk -F "," ' $2 >= 577 ' filename.csv > create_files
You can put the entire contents of the above content into a new file (I have named the new file as create_files
) and now you can create new files from this file.
After executing the above command, since, you have not mentioned any filename convention, I have assumed the first column can act as the file name. So, you can follow the approach as,
awk -F "," ' print $1 ' create_files | while read a; do touch $a; done
I am using the awk
command to extract the first column alone to have the file names and based on the first column I create the new files using the while
loop and touch
command.
However, I assume the first column will always be unique. If it is not unique, we may need to follow another approach. For that you need to edit your question and mention what file name convention you are planning on.
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
);
);
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%2f137929%2fcreating-a-file-from-another-file-on-the-basis-of-a-numeric-value-in-each-line%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
It can be done using the below command.
awk -F "," ' $2 >= 577 ' filename.csv > create_files
You can put the entire contents of the above content into a new file (I have named the new file as create_files
) and now you can create new files from this file.
After executing the above command, since, you have not mentioned any filename convention, I have assumed the first column can act as the file name. So, you can follow the approach as,
awk -F "," ' print $1 ' create_files | while read a; do touch $a; done
I am using the awk
command to extract the first column alone to have the file names and based on the first column I create the new files using the while
loop and touch
command.
However, I assume the first column will always be unique. If it is not unique, we may need to follow another approach. For that you need to edit your question and mention what file name convention you are planning on.
add a comment |
It can be done using the below command.
awk -F "," ' $2 >= 577 ' filename.csv > create_files
You can put the entire contents of the above content into a new file (I have named the new file as create_files
) and now you can create new files from this file.
After executing the above command, since, you have not mentioned any filename convention, I have assumed the first column can act as the file name. So, you can follow the approach as,
awk -F "," ' print $1 ' create_files | while read a; do touch $a; done
I am using the awk
command to extract the first column alone to have the file names and based on the first column I create the new files using the while
loop and touch
command.
However, I assume the first column will always be unique. If it is not unique, we may need to follow another approach. For that you need to edit your question and mention what file name convention you are planning on.
add a comment |
It can be done using the below command.
awk -F "," ' $2 >= 577 ' filename.csv > create_files
You can put the entire contents of the above content into a new file (I have named the new file as create_files
) and now you can create new files from this file.
After executing the above command, since, you have not mentioned any filename convention, I have assumed the first column can act as the file name. So, you can follow the approach as,
awk -F "," ' print $1 ' create_files | while read a; do touch $a; done
I am using the awk
command to extract the first column alone to have the file names and based on the first column I create the new files using the while
loop and touch
command.
However, I assume the first column will always be unique. If it is not unique, we may need to follow another approach. For that you need to edit your question and mention what file name convention you are planning on.
It can be done using the below command.
awk -F "," ' $2 >= 577 ' filename.csv > create_files
You can put the entire contents of the above content into a new file (I have named the new file as create_files
) and now you can create new files from this file.
After executing the above command, since, you have not mentioned any filename convention, I have assumed the first column can act as the file name. So, you can follow the approach as,
awk -F "," ' print $1 ' create_files | while read a; do touch $a; done
I am using the awk
command to extract the first column alone to have the file names and based on the first column I create the new files using the while
loop and touch
command.
However, I assume the first column will always be unique. If it is not unique, we may need to follow another approach. For that you need to edit your question and mention what file name convention you are planning on.
edited Jun 18 '14 at 23:11
answered Jun 18 '14 at 22:58
RameshRamesh
24k34105188
24k34105188
add a comment |
add a comment |
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%2f137929%2fcreating-a-file-from-another-file-on-the-basis-of-a-numeric-value-in-each-line%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
Please accept the answer if it works. Otherwise, please comment if you require more information.
– Sparhawk
Jun 25 '14 at 2:30