How to extract the first column in a file with multi-character delimeter?

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the nature of strings in the columns which may contain some of these special characters.
I want to extract the first column. I used:
cat myfile.txt | cut -d '<xxxxx>' -f1 > out.txt
But I got error saying that the delimeter must be a single character.
Q: How can I extract the first columns (which is before the first occurrence of <xxxxx>?
sed files string search
add a comment |
I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the nature of strings in the columns which may contain some of these special characters.
I want to extract the first column. I used:
cat myfile.txt | cut -d '<xxxxx>' -f1 > out.txt
But I got error saying that the delimeter must be a single character.
Q: How can I extract the first columns (which is before the first occurrence of <xxxxx>?
sed files string search
1
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12
add a comment |
I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the nature of strings in the columns which may contain some of these special characters.
I want to extract the first column. I used:
cat myfile.txt | cut -d '<xxxxx>' -f1 > out.txt
But I got error saying that the delimeter must be a single character.
Q: How can I extract the first columns (which is before the first occurrence of <xxxxx>?
sed files string search
I have a file in which I use a string like <xxxxx> to separate the fields. This was a choice to avoid problems with the comma separated fields and other types of single characters due to the nature of strings in the columns which may contain some of these special characters.
I want to extract the first column. I used:
cat myfile.txt | cut -d '<xxxxx>' -f1 > out.txt
But I got error saying that the delimeter must be a single character.
Q: How can I extract the first columns (which is before the first occurrence of <xxxxx>?
sed files string search
sed files string search
asked Mar 17 at 14:58
user9371654user9371654
31018
31018
1
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12
add a comment |
1
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12
1
1
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12
add a comment |
1 Answer
1
active
oldest
votes
With awk:
echo "This is it"|awk -F '<xxxxx>' 'print $1'
Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.
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%2f506825%2fhow-to-extract-the-first-column-in-a-file-with-multi-character-delimeter%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
With awk:
echo "This is it"|awk -F '<xxxxx>' 'print $1'
Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.
add a comment |
With awk:
echo "This is it"|awk -F '<xxxxx>' 'print $1'
Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.
add a comment |
With awk:
echo "This is it"|awk -F '<xxxxx>' 'print $1'
Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.
With awk:
echo "This is it"|awk -F '<xxxxx>' 'print $1'
Note that the field separator (argument to -F) is a regular expression, so if any characters in the separator are special in regexes, you'll need to escape them.
edited Mar 17 at 15:11
ilkkachu
63.4k10104181
63.4k10104181
answered Mar 17 at 15:05
JRFergusonJRFerguson
10.4k32632
10.4k32632
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%2f506825%2fhow-to-extract-the-first-column-in-a-file-with-multi-character-delimeter%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
1
CSV has rules for how to deal with fields containing commas and newlines etc. (quote fields, double up internal double quotes). Libraries for working with CSV data are readily available for most languages.
– Kusalananda♦
Mar 17 at 15:12