I am having csv file can I know how to replace spaces in column heading with underscore in linuxHow can I extract a predetermined range of lines from a text file on Unix?How can I profile C++ code running on Linux?How can I replace a newline (n) using sed?sed command with -i option failing on Mac, but works on LinuxAWK: replace space by underscore in 2nd columnHow to replace a particular column in a CSV with some string?Replace a column in a file but maintain the space formatHow to replace spaces with points at even positions in a line using linux commandReplacing spaces with underscores within quotesReplace ^A with space in Linux
How to cover method return statement in Apex Class?
How much character growth crosses the line into breaking the character
It grows, but water kills it
Is there an injective, monotonically increasing, strictly concave function from the reals, to the reals?
Using substitution ciphers to generate new alphabets in a novel
When were female captains banned from Starfleet?
Why can Carol Danvers change her suit colours in the first place?
Quoting Keynes in a lecture
Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?
Mixing PEX brands
Can a college of swords bard use blade flourish on an OA from dissonant whispers?
creating a ":KeepCursor" command
Why is it that I can sometimes guess the next note?
How can mimic phobia be cured?
Plot of a tornado-shaped surface
Is there a way to get `mathscr' with lower case letters in pdfLaTeX?
Quasinilpotent , non-compact operators
Does malloc reserve more space while allocating memory?
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Why did the EU agree to delay the Brexit deadline?
This is why we puzzle
What is the highest possible scrabble score for placing a single tile
Calculate sum of polynomial roots
How do I delete all blank lines in a buffer?
I am having csv file can I know how to replace spaces in column heading with underscore in linux
How can I extract a predetermined range of lines from a text file on Unix?How can I profile C++ code running on Linux?How can I replace a newline (n) using sed?sed command with -i option failing on Mac, but works on LinuxAWK: replace space by underscore in 2nd columnHow to replace a particular column in a CSV with some string?Replace a column in a file but maintain the space formatHow to replace spaces with points at even positions in a line using linux commandReplacing spaces with underscores within quotesReplace ^A with space in Linux
My actual input will be like this, in column heading I need linux command to replace spaces with underscores
INPUT:
patient name age number of days
santhosh 24 20
saravanan 23 25
EXPECTED OUTPUT:
patient_name age number_of_days
santhosh 24 20
saravanan 23 25
perl unix awk sed
add a comment |
My actual input will be like this, in column heading I need linux command to replace spaces with underscores
INPUT:
patient name age number of days
santhosh 24 20
saravanan 23 25
EXPECTED OUTPUT:
patient_name age number_of_days
santhosh 24 20
saravanan 23 25
perl unix awk sed
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like thisname_age?
– Tiw
Mar 7 at 6:44
1
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23
add a comment |
My actual input will be like this, in column heading I need linux command to replace spaces with underscores
INPUT:
patient name age number of days
santhosh 24 20
saravanan 23 25
EXPECTED OUTPUT:
patient_name age number_of_days
santhosh 24 20
saravanan 23 25
perl unix awk sed
My actual input will be like this, in column heading I need linux command to replace spaces with underscores
INPUT:
patient name age number of days
santhosh 24 20
saravanan 23 25
EXPECTED OUTPUT:
patient_name age number_of_days
santhosh 24 20
saravanan 23 25
perl unix awk sed
perl unix awk sed
edited Mar 7 at 6:43
Tiw
4,21361630
4,21361630
asked Mar 7 at 6:18
santhosh vsanthosh v
43
43
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like thisname_age?
– Tiw
Mar 7 at 6:44
1
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23
add a comment |
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like thisname_age?
– Tiw
Mar 7 at 6:44
1
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like this
name_age?– Tiw
Mar 7 at 6:44
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like this
name_age?– Tiw
Mar 7 at 6:44
1
1
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23
add a comment |
1 Answer
1
active
oldest
votes
OK, so assuming your CSV is tab delimited, I'd suggest what you want is split.
while ( <> )
print join "t", map s/s+/_/gr split /t/;
This will split on tabs, transform each 'entry' by replacing one or more spaces with underscores, and print the resultant line.
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap thetfor,and it'll work much the same.
– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just dosed -i 's/ /_/g' npidata.csv'. Butsedin that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.
– Sobrique
Mar 7 at 10:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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/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%2fstackoverflow.com%2fquestions%2f55037219%2fi-am-having-csv-file-can-i-know-how-to-replace-spaces-in-column-heading-with-und%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
OK, so assuming your CSV is tab delimited, I'd suggest what you want is split.
while ( <> )
print join "t", map s/s+/_/gr split /t/;
This will split on tabs, transform each 'entry' by replacing one or more spaces with underscores, and print the resultant line.
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap thetfor,and it'll work much the same.
– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just dosed -i 's/ /_/g' npidata.csv'. Butsedin that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.
– Sobrique
Mar 7 at 10:21
add a comment |
OK, so assuming your CSV is tab delimited, I'd suggest what you want is split.
while ( <> )
print join "t", map s/s+/_/gr split /t/;
This will split on tabs, transform each 'entry' by replacing one or more spaces with underscores, and print the resultant line.
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap thetfor,and it'll work much the same.
– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just dosed -i 's/ /_/g' npidata.csv'. Butsedin that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.
– Sobrique
Mar 7 at 10:21
add a comment |
OK, so assuming your CSV is tab delimited, I'd suggest what you want is split.
while ( <> )
print join "t", map s/s+/_/gr split /t/;
This will split on tabs, transform each 'entry' by replacing one or more spaces with underscores, and print the resultant line.
OK, so assuming your CSV is tab delimited, I'd suggest what you want is split.
while ( <> )
print join "t", map s/s+/_/gr split /t/;
This will split on tabs, transform each 'entry' by replacing one or more spaces with underscores, and print the resultant line.
answered Mar 7 at 9:29
SobriqueSobrique
48k54384
48k54384
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap thetfor,and it'll work much the same.
– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just dosed -i 's/ /_/g' npidata.csv'. Butsedin that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.
– Sobrique
Mar 7 at 10:21
add a comment |
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap thetfor,and it'll work much the same.
– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just dosed -i 's/ /_/g' npidata.csv'. Butsedin that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.
– Sobrique
Mar 7 at 10:21
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
my csv file is comma separater
– santhosh v
Mar 7 at 10:05
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap the
t for , and it'll work much the same.– Sobrique
Mar 7 at 10:09
Your example is not though. Your sample data in your question is tab separated. Either way though - you can swap the
t for , and it'll work much the same.– Sobrique
Mar 7 at 10:09
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
this is another way. head -1 npidata.csv | perl -pe "s/ /_/g" >npidata1.csv
– santhosh v
Mar 7 at 10:11
Well, you could just do
sed -i 's/ /_/g' npidata.csv'. But sed in that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.– Sobrique
Mar 7 at 10:21
Well, you could just do
sed -i 's/ /_/g' npidata.csv'. But sed in that scenario is blind to the delimiters, and isn't handling it as csv but rather plain text.– Sobrique
Mar 7 at 10:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55037219%2fi-am-having-csv-file-can-i-know-how-to-replace-spaces-in-column-heading-with-und%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
Kindly do mention what you have tried to solve your own problem in your post and let us know then.
– RavinderSingh13
Mar 7 at 6:22
Actually, my table consists of 20 columns along with 1500 data. My problem here is those column names have space in between them. I need to replace those spaces with an underscore.
– santhosh v
Mar 7 at 6:29
Show your own efforts first. Also what's the file separated with? How do we avoid the underscore been added like this
name_age?– Tiw
Mar 7 at 6:44
1
Are you sure your input is CSV? There's no commas in the sample you posted...
– Shawn
Mar 7 at 8:10
using awk, look to use printf and format (like "%9s") with field ( like $9). Put some try, we will help based on this
– NeronLeVelu
Mar 7 at 8:23