- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to keep lines with certain pattern and delete ...
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
07-27-2003 07:00 PM
07-27-2003 07:00 PM
I want to create a new file containing only lines with pattern '01' or '02' at 31 and 32 column.
hope you could help me, thank you for taking care of this message.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2003 07:59 PM
07-27-2003 07:59 PM
Re: how to keep lines with certain pattern and delete all the others
cat $file | awk '{FS=":"; if ($31 == "01" && $32 == "02") { print $0}}' >> $new_file
replace the : with whatever your Field Seperator is. If it is blanks then leave out the whole FS piece up to the ;
Else, if you want column 31 and 32 to be either 01 or 02 then try this:
cat $file | awk '{FS=":"; if ($31 == "01 || $31 == "02") { if ($32 == "01" || $32 == "02") {print $0}}' >> $new_file
Again, replace the : with your field seperator.
-Ronelle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2003 08:05 PM
07-27-2003 08:05 PM
Re: how to keep lines with certain pattern and delete all the others
cat $file | awk '{if (($31 == "01" || $31 == "02") && ($32 == "01" || $32 == "02")) {print $0}}' >> $new_file
Much simpler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2003 06:01 AM
07-28-2003 06:01 AM
Solutionsed -n -e '/^.\{30\}0[12]/p' largefile >only3x
Here is a break down of the regular expression (what's between '/' and the next '/')-
^ matches beginning of string
.\{30\} matches the first 30 anything
0 matches a 0 in column 31
[12] matches either a 1 or 2 in column 32
The -n option prevents sed from outputing the lines unless explicitly stated (ie "p")
You could use "awk" by using the "substr" function (ie substr($0,30,2)=="01"). The default field seperator is blank/tab, but you can look at the whole line with $0.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2003 04:41 PM
07-28-2003 04:41 PM
Re: how to keep lines with certain pattern and delete all the others
you've solved my problem. The script is just what I need.
and for Ronelle,
sorry, there are no separators between columns. each charactor is one column.
thank you all for taking the time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2005 09:28 PM
08-25-2005 09:28 PM