Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Clearing leading and trailing blanks from a string in C Shell

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-01-2012   -   Original Discussion by phudgens
phudgens's Unix or Linux Image
phudgens phudgens is offline
Registered User
 
Join Date: Feb 2009
Last Activity: 3 May 2012, 11:30 AM EDT
Location: Denver
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Clearing leading and trailing blanks from a string in C Shell

Does anyone know of a way with C Shell that will work on both Linux and Sun to clear all leading and trailing blanks from a previously specified string? I am using the following code to replace blanks with underscores:

Code:
set Company = `echo $Company | sed 's/ /_/g

but I don't want any leading or trailing underscores. The string was originally defined using:

Code:
set COMPLine = `grep  -i "COMPANY" $LASInputFile`
set Company = `echo $COMPLine | sed 's/^[^ ][^ ]* *\([^:][^:]*\)[ ][ ]*:.*/\1/'`

Thanks for any help
Sponsored Links
    #2  
Old Unix and Linux 05-01-2012   -   Original Discussion by phudgens
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 7 December 2017, 5:57 PM EST
Posts: 3,424
Thanks: 147
Thanked 1,212 Times in 1,112 Posts
How about this:


Code:
# echo "  Acme Consultants Pty Ltd   " | sed -e 's/^ *//' -e 's/ *$//' -e 's/ /_/g'
Acme_Consultants_Pty_Ltd


Last edited by Chubler_XL; 05-01-2012 at 06:44 PM.. Reason: Fixed line wrap
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove trailing and leading spaces using tr command sureshg_sampat Shell Programming and Scripting 5 03-04-2009 05:04 AM
how to remove trailing blanks, tabs aoussenko Shell Programming and Scripting 3 07-01-2008 12:12 PM
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
FTP Between UNIX & Windows drops leading blanks worf52 UNIX for Advanced & Expert Users 6 02-15-2005 08:03 AM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 11:48 PM



All times are GMT -4. The time now is 10:16 PM.