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;
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
add a comment
|
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
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
add a comment
|
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
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
command-line bash scripts awk
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
add a comment
|
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
add a comment
|
1 Answer
1
active
oldest
votes
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:
Your file is comma separated. Thus, you need to specify
-F,so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,.The first argument to
sub(orgsub) should be a regular expression not a string. In our case the regular expression should matchTand everything after..*means everything after.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
add a comment
|
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
);
);
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%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
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:
Your file is comma separated. Thus, you need to specify
-F,so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,.The first argument to
sub(orgsub) should be a regular expression not a string. In our case the regular expression should matchTand everything after..*means everything after.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
add a comment
|
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:
Your file is comma separated. Thus, you need to specify
-F,so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,.The first argument to
sub(orgsub) should be a regular expression not a string. In our case the regular expression should matchTand everything after..*means everything after.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
add a comment
|
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:
Your file is comma separated. Thus, you need to specify
-F,so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,.The first argument to
sub(orgsub) should be a regular expression not a string. In our case the regular expression should matchTand everything after..*means everything after.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
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:
Your file is comma separated. Thus, you need to specify
-F,so that, on input, each line is divided into fields based on commas.Since you want a comma-separated file on output, we also need to specify
OFS=,.The first argument to
sub(orgsub) should be a regular expression not a string. In our case the regular expression should matchTand everything after..*means everything after.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
answered Sep 30 at 7:13
John1024John1024
11.1k30 silver badges40 bronze badges
11.1k30 silver badges40 bronze badges
add a comment
|
add a comment
|
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.
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%2faskubuntu.com%2fquestions%2f1177595%2fremove-words-from-a-column-in-a-file%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
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