- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- In perl, how to modify all but 1st 2 lines in text...
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
05-25-2006 02:32 AM
05-25-2006 02:32 AM
perl -pi -e 's/^/{/g' datafile.txt
perl -pi -e 's/$/}/g' datafile.txt
It modifies all lines.
Need a perl command to insert { before each line and } after end of each line for all lines beginning and ending with "
======================
#cat datafile.txt
Table Contact
id, c_contact_num, c_notes
"11510474","adrian4"," "
"192031","roberto"," "
....
....
should look like this after executing the perl command. Prefer not to use sed as I have to redirect the output to another file
#cat datafile.txt
Table Contact
id, c_contact_num, c_notes
{"11510474","adrian4"," "}
{"192031","roberto"," "}
....
....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 02:42 AM
05-25-2006 02:42 AM
Solution# perl -pi.old -e 's/^"/("/;s/"$/")/' file
...and in "file.old" will be a backup copy of your original (unmodified) file. If you don't want a copy retained, do:
# perl -pi -e 's/^"/("/;s/"$/")/' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 02:52 AM
05-25-2006 02:52 AM
Re: In perl, how to modify all but 1st 2 lines in text file ?
Ooops you wanted curly braces, not parentheses:
# perl -pi.old -e 's/^"/{"/;s/"$/"}/' file
...and in "file.old" will be a backup copy of your original (unmodified) file. If you don't want a copy retained, do:
# perl -pi -e 's/^"/{"/;s/"$/"}/' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 02:55 AM
05-25-2006 02:55 AM
Re: In perl, how to modify all but 1st 2 lines in text file ?
For my perl knowledge, how would you convert following sed to perl.
sed -e '1,3s/^/TEST/g' file > file1
In perl, need to know how to modify just 1 thru 3 lines
The command below failed:
perl -pi -e '1,3s/^/TEST/g' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 02:56 AM
05-25-2006 02:56 AM
Re: In perl, how to modify all but 1st 2 lines in text file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 03:09 AM
05-25-2006 03:09 AM
Re: In perl, how to modify all but 1st 2 lines in text file ?
Perl's motto is "TMTOWTDI" [ Google that if you don't know :-) ], so here's one
# perl -pe 's/^/TEST/ if $. <= 3' file
...in lieu of:
# sed -e '1,3s/^/TEST/g' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 03:18 AM
05-25-2006 03:18 AM
Re: In perl, how to modify all but 1st 2 lines in text file ?
Appreciate it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2006 03:25 AM
05-25-2006 03:25 AM