sed command playing with me! | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

sed command playing with me!

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-14-2012
Error404 Error404 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 February 2014, 10:42 AM EST
Posts: 24
Thanks: 14
Thanked 0 Times in 0 Posts
Display sed command playing with me!

Hello guys,

I was working with my data (a tab delimted text file) in Linux and wanted to replace all "NaN" values in my huge table with "NA", so i used the following sed command:


Code:
sed 's/NaN/NA/g' /filepath -> outputfile.txt

The results were good, all "NaN" were replaced with "NA", but the new output file had no headers no column names anymore!

Example:
Before:

Code:
V12 V13 V14 V15 V16
100 200 300 NaN 500
220 NaN 100 500 600
700 NaN 900 100 200

After:

Code:
100 200 300 NA 500
220 NA 100 500 600
700 NA 900 100 200

Any idea what happened? what is the right command to use here?

Many thanks,
Error404


Moderator's Comments:
Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by zaxxon; 11-14-2012 at 05:43 AM.. Reason: code tags
Sponsored Links
    #2  
Old 11-14-2012
bmk bmk is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 31 October 2013, 9:16 AM EDT
Posts: 262
Thanks: 1
Thanked 22 Times in 22 Posts
it's valid sed command..i tried it's working fine..
Sponsored Links
    #3  
Old 11-14-2012
Error404 Error404 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 February 2014, 10:42 AM EST
Posts: 24
Thanks: 14
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by bmk View Post
it's valid sed command..i tried it's working fine..
bmk,
Yes it is working. as you can see, it converts all "NaN" to "NA".
but the problem i am having now that it is omitting the headers, didn't that happen with you too?

-Error404
    #4  
Old 11-14-2012
bmk bmk is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 31 October 2013, 9:16 AM EDT
Posts: 262
Thanks: 1
Thanked 22 Times in 22 Posts
See my output...

Code:
V12 V13 V14 V15 V16
100 200 300 NA 500
220 NA 100 500 600
700 NA 900 100 200

The Following User Says Thank You to bmk For This Useful Post:
Error404 (11-14-2012)
Sponsored Links
    #5  
Old 11-14-2012
hergp hergp is offline Forum Advisor  
Problem Eliminator
 
Join Date: Jan 2010
Last Activity: 18 April 2014, 11:10 AM EDT
Location: Vienna, Austria
Posts: 780
Thanks: 16
Thanked 165 Times in 147 Posts
Check your input file for non printable characters, especially at the beginning around the header line. You can use


Code:
od -c inputfile | head

for this.
The Following User Says Thank You to hergp For This Useful Post:
Error404 (11-14-2012)
Sponsored Links
    #6  
Old 11-14-2012
Error404 Error404 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 18 February 2014, 10:42 AM EST
Posts: 24
Thanks: 14
Thanked 0 Times in 0 Posts
Hey guys,
This data is spooky! :|
I tried to do the same sed command to another file and it worked properly. Then tried to do THE EXACT COMMAND to this file again, and it still omitted the columns names!!! :S
I guess I will have to try to export another huge set of data to see whats wrong!
I'll let you know if the set of data i am going to export will do this problem again

Thanks guys, your help is appreciated
-Error404
Sponsored Links
    #7  
Old 11-14-2012
bmk bmk is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 31 October 2013, 9:16 AM EDT
Posts: 262
Thanks: 1
Thanked 22 Times in 22 Posts
or else simply take the first column append to output file.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Playing with parameters arturo322 Shell Programming and Scripting 2 02-21-2011 12:16 AM
Crontab not playing Fitch UNIX for Dummies Questions & Answers 2 01-28-2011 12:14 PM
sed scripts are not playing nicely! naphelge Shell Programming and Scripting 4 06-29-2010 01:55 PM
ffmpeg: capture audio that's playing (command line) sentinel UNIX for Dummies Questions & Answers 0 02-09-2010 09:47 AM
Loop with sed command to replace line with sed command in it cbo0485 Shell Programming and Scripting 1 08-27-2009 11:19 AM



All times are GMT -4. The time now is 08:10 AM.