- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Need some shell script advise about preserving bla...
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
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
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
08-16-2001 10:18 AM
08-16-2001 10:18 AM
I need to preserve these blank spaces. I can run the following command at a command line:
# tail -1 FILENAME
and get the correct result: "Mary had a little lamb"
However, when I try to move the contents into a shell script variable, it removes all extra blank spaces.
# A=`tail -1 FILENAME`
# echo $A
my results are:
"Mary had a little lamb"
Does anyone know a work around for this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 10:26 AM
08-16-2001 10:26 AM
Re: Need some shell script advise about preserving blank spaces
Could you please post exactly what you want and what you are getting?
Thanks,
...jcd...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 10:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 10:38 AM
08-16-2001 10:38 AM
Re: Need some shell script advise about preserving blank spaces
I am not sure if I understood your question correctly. I couldn't see any blank spaces anywhere. I would do the following.
cat file |sed 's/ /#/g' > /tmp/file$$
A=`tail -1 /tmp/file$$ |sed 's/#/ /g'`
I am not sure if this helps.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 10:39 AM
08-16-2001 10:39 AM
Re: Need some shell script advise about preserving blank spaces
I played with a sample file and an little script, and I was able to reproduce your problem. I hacked on it a little bit and I was able to get a shell script to read all of the line into a variable, including spaces. The trick was to set the IFS variable to null. That variable contains the characters that separate a word, and normally the space character is a word separator. By setting it to null, the shell thinks that the entire line is a single word and puts it all into the variable.
It looks like this:
fduxdd01:/home/users/jpoff/junk>cat mary.txt
Here is
some text
Mary had a little lamb
fduxdd01:/home/users/jpoff/junk>cat marytest.sh
#!/bin/sh
# marytest.sh
tail -1 mary.txt | wc
IFS="" MYLINE=$(tail -1 mary.txt)
echo $MYLINE
echo $MYLINE | wc
fduxdd01:/home/users/jpoff/junk>./marytest.sh
1 5 29
Mary had a little lamb
1 5 29
There is probably a neater way to do it, but this is my hack at it. I hope this helps.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 10:44 AM
08-16-2001 10:44 AM
Re: Need some shell script advise about preserving blank spaces
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2001 02:02 PM
08-16-2001 02:02 PM
Re: Need some shell script advise about preserving blank spaces
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 02:59 PM
08-18-2001 02:59 PM
Re: Need some shell script advise about preserving blank spaces
you could set your $IFS to only tabs and then use only
tabs in your command line - that way spaces are *real*
text and not delimiters...
HTH,
Wodisch