- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Putting Double Quotes in a text 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
04-04-2002 10:45 AM
04-04-2002 10:45 AM
I'm not sure if this was asked before But I tried searching the forum and could'nt find one. Anyways, I have a txt file and wanted to put a double quotes on every numbers within the column. Example
THis is the original file
201,303,412,484,576
202,306,413,485,578
and I want it to be as this one
"201","303","412","484","576"
"202","306","413","485","578"
Your help would be greatly appreciated
THanks
Joey
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 10:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 10:50 AM
04-04-2002 10:50 AM
Re: Putting Double Quotes in a text file
sed -e 's/,/","/g;s/^/"/;s/$/"/'
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 11:12 AM
04-04-2002 11:12 AM
Re: Putting Double Quotes in a text file
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 11:14 AM
04-04-2002 11:14 AM
Re: Putting Double Quotes in a text file
Same thing can be done via vi editor.
In escape mode:
%s/,/","/g
%s/^/"/
%s/$/"/
HTH
raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 11:31 AM
04-04-2002 11:31 AM
Re: Putting Double Quotes in a text file
201,303,888412,484,576
101,403,712,884,9999876,3,44
then this will work:
cat infile | sed "s/\([0-9]\{1,\}\)/\"\1\"/g"
producing this:
"201","303","888412","484","576"
"101","403","712","884","9999876","3","44"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 12:05 PM
04-04-2002 12:05 PM
Re: Putting Double Quotes in a text file
Here is another way with sed:
This will prefix and suffix any number of numeric characters with double quotes:
sed 's/[0-9]*/"&"/g' filename
Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 12:14 PM
04-04-2002 12:14 PM
Re: Putting Double Quotes in a text file
Use of "*" matches null to, so you need to modify your sed with-
sed 's/[0-9]\{1,\}/"&"/g'
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 12:21 PM
04-04-2002 12:21 PM
Re: Putting Double Quotes in a text file
perl -pi -e 's/\d+/"$&"/g' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2002 12:21 PM
04-04-2002 12:21 PM
Re: Putting Double Quotes in a text file
Thanks Rodney for pointing it out ...
Joey,
This will also match blanks as mentioned by Rodney "*" matches null also... Thanks for the points.
N/A for this please ..
-Shabu