- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Formatting
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-21-2002 01:48 PM
тАО07-21-2002 01:48 PM
I have a text data file. I want to delete part of the file contents. Anything between START and END I want to delete.
EX:
line1
line2
START
line3
-
-
Line7
END
some lines
START
some lines
END
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 02:06 PM
тАО07-21-2002 02:06 PM
SolutionAssuming you want not only delete the lines between START and END, but also START and END themselves, you can use the following:
awk '{if ($1=="START") del=1;
if (del!=1) print $0;
if ($1=="END") del=0;
}' DATAFILE
In case you want to leave the START-END lines itselve, you should use:
awk '{ if ($1=="END") del=0;
if (del!=1) print $0;
if ($1=="START") del=1;
}' DATAFILE
Regards,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 02:30 PM
тАО07-21-2002 02:30 PM
Re: Formatting
#!/bin/sh
check=0
while read line
do
if [ "$line" = "START" ]
then
check=1
elif [ "$line" = "END" ]
then check=0
elif [ $check -eq 0 ]
then
echo $line
fi
done < data.txt
regards.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 06:03 PM
тАО07-21-2002 06:03 PM
Re: Formatting
Here's another way:
# cat datafile | tr ["\n"] [+] | perl -e 'while (
This is assuming that you don't have a plus (+) sign in any of your text. + can be replaced by any other separator character not found in your needed text.
# cat datafile
this is line 1
this is line 2
START
this is line 3
this is line 4
this is line 5
this is line 6
END
this is line 8
START
this is line 10
END
# cat datafile | tr ["\n"] [+] | perl -e 'while (
this is line 1
this is line 2
this is line 8
Hope this helps. Regards.
Steven Sim Kok Leong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 09:50 PM
тАО07-21-2002 09:50 PM
Re: Formatting
line1
line2
START
line3
-
-
Line7
END
some lines 1
START
some lines 2
END
l1:/tmp 119 > perl -ne '/^START/../^END/ or print' xx
line1
line2
some lines 1
l1:/tmp 120 >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2002 10:04 PM
тАО07-21-2002 10:04 PM
Re: Formatting
It is working fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2002 03:12 AM
тАО07-22-2002 03:12 AM
Re: Formatting
sed '/START/,/END/d' output