- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Formatting File
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-29-2000 10:38 AM
08-29-2000 10:38 AM
I have an ASCII flat file which has a lot of white space ( spaces ) in between the fields. The field separators are quoted comma ( "," ). How can I remove these spaces between the field separators using something like sed, awk or tr?
A specific example or answer would be nice.
Thanks,
Sanjay.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 10:47 AM
08-29-2000 10:47 AM
Re: Formatting File
You can "squeeze" multiple blanks down to one with 'tr'. For example"
# echo "xxx yyy zzz"|tr -s " " " "
yields "xxx yyy zzz"
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 10:49 AM
08-29-2000 10:49 AM
Re: Formatting File
sed "s/~$//p" INFILE > OUTFILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 10:58 AM
08-29-2000 10:58 AM
Re: Formatting File
echo "aaa bbb ccc" yeilds
aaa bbb ccc
echo "aaa bbb ccc" | tr -s " " yeilds
aaa bbb ccc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:26 AM
08-29-2000 11:26 AM
Re: Formatting File
Can you attach a small file so that we can get you the right solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:47 AM
08-29-2000 11:47 AM
Re: Formatting File
With the suggestion from James, I got the fileds down form multiple to single spaces. I tried what you suggested using sed and it did work. Yet one of my fields is a title ( example "The Calculus Book." When I ran sed it got rid of all the spaces including the one in the title. Like I said my field separators are "," My spaces are on either sides of these. Can write something in sed to just take out the spaces here?
Thanks,
Sanjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:56 AM
08-29-2000 11:56 AM
Re: Formatting File
sed 's/[ ]*,[ ]*/ , /g' t
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:57 AM
08-29-2000 11:57 AM
Re: Formatting File
sed 's/[ ]*,[ ]*/,/g' t
if you want no spaces at all around the commas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:58 AM
08-29-2000 11:58 AM
Re: Formatting File
Try this
sed -e 's/ *(",") */1/g' inpfile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 11:59 AM
08-29-2000 11:59 AM
Re: Formatting File
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2000 12:06 PM
08-29-2000 12:06 PM
Re: Formatting File
I tried what Anthony suggested and got the spaces removed everywhere. I then tried:
sed 's/ "," /","/g' file1 > file2
And it worked!!! This seems to be the format I am looking for.
Thank you.
Sanjay.