The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need help in replacing spaces in a file sais Shell Programming and Scripting 7 10-06-2008 10:24 AM
Replacing leading zeros with leading spaces deepakwins UNIX for Dummies Questions & Answers 5 06-18-2008 03:06 AM
replacing tabs to spaces from files rishir Shell Programming and Scripting 6 12-15-2005 01:12 PM
finding & replacing blank rows/spaces in a file Gerry405 SUN Solaris 2 07-21-2005 05:49 AM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-10-2008
Amey Joshi Amey Joshi is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 50
Replacing the Spaces

Hi,

i have a tab dilimeted file.The records are :header is having column names.I am facing the following issue :
I want to convert the spaces only for header file into "_" in the unix shell but the problem is that if i use sed command all the blank spaces are getting replaced by "_".
For example:head -1 samlpe.txt
EMP ID EMP NAME EMP DETAIL EMP CONTACT EMP LOCATION
Want to Convert into
EMP_ID EMP_NAME EMP_DETAIL EMP_CONTACT EMP_LOCATION

Can anybody help regarding this?
Thanks in Advance!
  #2 (permalink)  
Old 11-11-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink What about


Code:
echo $header | sed "s/EMP /EMP_/g"

or

Code:
head -1 sample.txt | sed "s/EMP /EMP_/g"

  #3 (permalink)  
Old 11-11-2008
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
using perl:
Code:
perl -pi -e 's/EMP /EMP_/g  if ($. == 1);' filename

  #4 (permalink)  
Old 11-11-2008
sivakumar.rj sivakumar.rj is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 74
Can you explain in detail how perl works and what is the benefit of perl when compared to sed and awk commands.......
Closed Thread

Bookmarks

Tags
perl regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0