- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Adding Single Quotes
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
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
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
тАО06-11-2009 01:45 PM
тАО06-11-2009 01:45 PM
'xxxxxx'
currently its just xxxxxx and there are 2000 enteries in all for which I need to add the quotes to.
Currently the file is like this -
xxxxxx
xxxxxx
xxxxxx
.
.
.
xxxxxx
and want to change this to -
'xxxxxx'
.
.
.
.
'xxxxxx'
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 01:55 PM
тАО06-11-2009 01:55 PM
Re: Adding Single Quotes
http://www.unix.com/unix-dummies-questions-answers/73879-add-single-quotes-string.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 01:56 PM
тАО06-11-2009 01:56 PM
Solution# cat ./myfile
this is something
another
thing 1
thing 2
here is more
# perl -pe 's/(\S+)/\047$1\047/g' myfile
'this' 'is' 'something'
'another'
'thing' '1'
'thing' '2'
'here' 'is' 'more'
...and if you want an inplace update:
# perl -pi.old -e 's/(\S+)/\047$1\047/g' myfile
...which automatically backs up the unchanged file as 'myfile.old' too.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 02:06 PM
тАО06-11-2009 02:06 PM
Re: Adding Single Quotes
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 02:13 PM
тАО06-11-2009 02:13 PM
Re: Adding Single Quotes
The regex substitutes a non-whitespace character sequence with a single quote, the character sequence and another single quote. A non-whitespace character is denoted by '\S'. The '+' says one or more of them. The parenthesis capture what is seen and the '\1' is a backreference to what was last captured. The '\047' is the Ascii code for a single quote which makes commandline substitution easier to do. The 'g' says to "g"lobally repeat the substitution as many times as necessary on each line.
Please don't forget to re-open this thread to evaluate these answers :-)
Regards!
...JRF...
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 02:20 PM
тАО06-11-2009 02:20 PM
Re: Adding Single Quotes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-11-2009 10:16 PM
тАО06-11-2009 10:16 PM
Re: Adding Single Quotes
:%s/^/'/
:%s/$/'/
Translating to sed:
sed -e "s/^/'/" -e "s/$/'/" file
Or harder:
sed -e "s/^\(.*\)\$/\'\1'/" file