👤
Home Man
Search
Today's Posts
Register

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

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 05-01-2012
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
# 2  
Old 05-01-2012
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 05:44 PM.. Reason: Fixed line wrap
👤 Login to reply

« Previous Thread | Next 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
Remove leading and trailing spaces from a file svajhala Shell Programming and Scripting 9 07-13-2017 04:56 PM
Remove the leading and trailing date from a CSV file shivamayam Shell Programming and Scripting 7 07-13-2017 12:12 PM
Leading blanks lazybaer Shell Programming and Scripting 6 03-01-2013 01:27 PM
Help to move leading negative sign to trailing position selvankj Shell Programming and Scripting 11 07-07-2011 08:35 AM
Removing leading and trailing spaces only in PERL kumar04 Shell Programming and Scripting 2 04-04-2009 03:17 PM
remove trailing and leading spaces using tr command sureshg_sampat Shell Programming and Scripting 5 03-04-2009 04:04 AM
how to remove trailing blanks, tabs aoussenko Shell Programming and Scripting 3 07-01-2008 11:12 AM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 01:24 PM
FTP Between UNIX & Windows drops leading blanks worf52 UNIX for Advanced & Expert Users 6 02-15-2005 07:03 AM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 10:48 PM


All times are GMT -4. The time now is 09:36 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password