Remove characters between "-".

Programming languages, Coding, executables, and scripting.
Post Reply
Message
Author
hack3rcon
Posts: 530
Joined: 2015-02-16 09:54

Remove characters between "-".

#1 Post by hack3rcon »

Hello,
I have a lot of names with Date characters front of them:

Code: Select all

Char1	2020-10-28
Char2	2020-10-28
Char3	2020-10-28
Char4	2020-10-16
Char5	2020-10-28
Char6	2020-10-26
I want to have a Bash script that remove all these dates.

Thank you.

User avatar
Bloom
Posts: 362
Joined: 2017-11-11 12:23

Re: Remove characters between "-".

#2 Post by Bloom »

If data.txt contains your data, just do:

Code: Select all

cut -d " " -f 1 data.txt
If you want to save the output, add '>newfile.txt' after data.txt.

hack3rcon
Posts: 530
Joined: 2015-02-16 09:54

Re: Remove characters between "-".

#3 Post by hack3rcon »

Bloom wrote:If data.txt contains your data, just do:

Code: Select all

cut -d " " -f 1 data.txt
If you want to save the output, add '>newfile.txt' after data.txt.
Not worked.

User avatar
Bloom
Posts: 362
Joined: 2017-11-11 12:23

Re: Remove characters between "-".

#4 Post by Bloom »

If in front of the dates, a tab is present, replace the -d " " by -d\t or remove the option (tab is the default separator for cut).

hack3rcon
Posts: 530
Joined: 2015-02-16 09:54

Re: Remove characters between "-".

#5 Post by hack3rcon »

Bloom wrote:If in front of the dates, a tab is present, replace the -d " " by -d\t or remove the option (tab is the default separator for cut).
Thank you.
It was a tab and

Code: Select all

cut -f 1 "File Name"
solve it.

Post Reply