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













-1















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









share|improve this question
























  • 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















-1















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









share|improve this question
























  • 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













-1












-1








-1








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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

















  • 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
















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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer























  • 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











  • 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










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
);



);













draft saved

draft discarded


















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









1














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.






share|improve this answer























  • 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











  • 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















1














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.






share|improve this answer























  • 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











  • 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













1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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 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











  • 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

















  • 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











  • 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
















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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович