- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Deleting line in a 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
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
тАО07-11-2006 06:47 PM
тАО07-11-2006 06:47 PM
Deleting line in a file
I have a file that contain a line below:
...
Test,1
Code,
Test,2
...
What i want to do is delete the Code, part
so the the file will look like this:
...
Test,1
Test,2
...
Is there a one line command to do this?
Maximum point to all correct answers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 06:54 PM
тАО07-11-2006 06:54 PM
Re: Deleting line in a file
it's possible with editor vi
vi "file"
"dd" for suppress line
or
substitution
s/chaine1/chaine2/[g]
s/code/""/g
In attachment, vi instructions
regards
L-DERLYN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 07:18 PM
тАО07-11-2006 07:18 PM
Re: Deleting line in a file
If it's not context sensative, and you just want all lines that look like "Code," be removed,
# perl -ni.org -e'/^Code,$/ or print' file
or
# mv file file.org
# grep -v '^Code,$' file.org >file
The original file will be backed up as file.org
If the removal however is based on context, you need some more. Then it also depends on how big the file is
If the context is just the line before, it's still rather simple
# perl -ni.org -e'$p eq"Test,1\n"&&/^Code,$/ or print;$p=$_' file
If the file is small (for any value of small, which mainly depends on your available system resources), and you want the removal based on the line before *and* after, there are many solutions
# perl -pi.org -e'BEGIN{$/=undef}s{(\A|\n)(Test,1\n)Code,\n(Test,2\n)}{$1$2$3}g' file
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 07:43 PM
тАО07-11-2006 07:43 PM
Re: Deleting line in a file
thanks for the input.
what if i dont want to have a backup copy?
what should be the perl command / syntax?
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 08:57 PM
тАО07-11-2006 08:57 PM
Re: Deleting line in a file
# perl -pi -e'....' file
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-11-2006 09:02 PM
тАО07-11-2006 09:02 PM
Re: Deleting line in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 02:27 PM
тАО07-12-2006 02:27 PM
Re: Deleting line in a file
# perl -pi -e'/^Code,$/ or print' file
but the results was:
Test,1
Test,1
Code,
Test,2
Test,2
It does nor remove the Code, but added another line? I might have understood you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 02:54 PM
тАО07-12-2006 02:54 PM
Re: Deleting line in a file
# sed '/Code/ d' source_file target_file
Hope it can help
twang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2006 06:28 PM
тАО07-12-2006 06:28 PM
Re: Deleting line in a file
# perl -ni -e'/^Code,$/ or print' file
it is -ni, not -pi
Mea Culpa
Enjoy, Have FUN! H.Merijn