- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need to remove trailing spaces
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 12:48 AM
тАО03-20-2007 12:48 AM
I am just trying to set a variable to be the model type of the system using the following:-
MODEL=`model | awk -F "[/]" '{print $3}'`
The problem I have is that on certain systems such as an RP4440 that actually produces a variable with 2 trailing spaces after it. I can't really use cut as the model strings vary. How can I simply remove the trailing spaces.
Thanks
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 12:55 AM
тАО03-20-2007 12:55 AM
Re: Need to remove trailing spaces
# delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' # '\t'=tab (see note at end of file)
Pete
Pete
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 12:57 AM
тАО03-20-2007 12:57 AM
Re: Need to remove trailing spaces
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
awk '{sub(/^[ \t]+/, ""); print}'
# delete trailing whitespace (spaces, tabs) from end of each line
awk '{sub(/[ \t]+$/, "");print}'
# delete BOTH leading and trailing whitespace from each line
awk '{gsub(/^[ \t]+|[ \t]+$/,"");print}'
awk '{$1=$1;print}' # also removes extra space between fields
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 12:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 02:07 AM
тАО03-20-2007 02:07 AM
Re: Need to remove trailing spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 08:06 PM
тАО03-20-2007 08:06 PM
Re: Need to remove trailing spaces
it's strange. I run same command and the result on my HPux11i it's fine:
%MODEL=`model | awk -F "[/]" '{print $3}'`
%echo "#$MODEL#"
#rp7420#
I also simulate the trouble using a var with spaces at the end but the result it's fine as well:
%x="9000/800/rp7420 "
%echo "#$x#"
#9000/800/rp7420 #
%MODEL=`echo $x | awk -F "[/]" '{print $3}'`
%echo "#$MODEL#"
#rp7420#
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 08:49 PM
тАО03-20-2007 08:49 PM
Re: Need to remove trailing spaces
Send the output of model to a file and see if trailing spaces.
>Art: I also simulate the trouble using a var with spaces at the end but the result is fine as well:
MODEL=`echo $x | awk -F "[/]" '{print $3}'`
This isn't valid simulation. If you change to the following to quote the variable $x, you will preserve the spaces:
MODEL=$(echo "$x" | awk -F "[/]" '{print $3}'); echo "$MODEL x"
Also the scummy C shell seems to strip the trailing spaces because the result of `` has trailing whitespaces removed. But not a real shell.
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-20-2007 09:51 PM
тАО03-20-2007 09:51 PM
Re: Need to remove trailing spaces
/root]MODEL=`model | awk -F "[/]" '{print $3}'`
root:/root]echo $MODEL
rp4440
root@meskpweb:/root]echo "$MODEL adam"
rp4440 adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2007 12:14 AM
тАО03-21-2007 12:14 AM
Re: Need to remove trailing spaces
your space is located between the two string in the string presented to the echo command: "$MODEL adam"
root@meskpweb:/root]echo "$MODEL adam"
rp4440 adam
try
echo ":$MODEL:"
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2007 03:05 AM
тАО03-21-2007 03:05 AM
Re: Need to remove trailing spaces
root@:/root]MODEL=`model | awk -F "[/]" '{print $3}'`
root@:/root]echo $MODEL
rp4440
root@meskpweb:/root]echo "$MODEL adam"
rp4440 adam
root@:/root]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2007 03:08 AM
тАО03-21-2007 03:08 AM
Re: Need to remove trailing spaces
O well trust me its there on the unix box as when I create my output all servers are fine apart from this one which has two spaces before the next variable. Anyway the problem is fixed and I am going mad.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2007 05:15 AM
тАО03-21-2007 05:15 AM
Re: Need to remove trailing spaces
The forum webpage/software is nasty that way.
Multiple tabs/spaces are condended to 1 space UNLESS you check the box for:
"Retain format(spacing). URLs will not be clickable"
When discussing a problem where exact input or output format is critical it is best to attach a ".txt" file with clear examples of what is shown and how it should be transformed.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-21-2007 08:52 PM
тАО03-21-2007 08:52 PM