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

Tags
shell scripts

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 06: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
How to remove leading and trailing spaces for variable in shell script? pottic Shell Programming and Scripting 10 3 Weeks Ago 11:39 PM
Remove leading and trailing spaces from a file svajhala Shell Programming and Scripting 9 07-13-2017 05:56 PM
Remove the leading and trailing date from a CSV file shivamayam Shell Programming and Scripting 7 07-13-2017 01:12 PM
Leading blanks lazybaer Shell Programming and Scripting 6 03-01-2013 02:27 PM
Removing leading and trailing spaces only in PERL kumar04 Shell Programming and Scripting 2 04-04-2009 04:17 PM
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:13 PM.

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