- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripting question: Filtering certain fields and ...
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
11-02-2007 05:57 PM
11-02-2007 05:57 PM
Here is the data file:
---------------------------------------------
0769 021E c4t3d3/14A c9t3d3/08B c11t3d3/09A c17t3d3/03B
0769 0256 c4t4d2/14A c9t4d2/08B c11t4d2/09A c17t4d2/03B
0769 0296 c4t5d2/14A c9t5d2/08B c11t5d2/09A c17t5d2/03B
0769 0326 c4t7d4/14A c9t7d4/08B c11t7d4/09A c17t7d4/03B
0769 0356 c4t8d2/14A c9t8d2/08B c11t8d2/09A c17t8d2/03B
0769 03DE c4t10d3/14A c9t10d3/08B c11t10d3/09A c17t10d3/03B
0769 042E c4t11d5/14A c9t11d5/08B c11t11d5/09A c17t11d5/03B
0769 048E c4t13d1/14A c9t13d1/08B c11t13d1/09A c17t13d1/03B
0769 04D6 c4t14d2/14A c9t14d2/08B c11t14d2/09A c17t14d2/03B
0769 05A6 c19t1d0/09A c20t1d0/08B c21t1d0/14A c22t1d0/03B
0769 05C6 c19t1d4/09A c20t1d4/08B c21t1d4/14A c22t1d4/03B
0769 0656 c19t3d6/09A c20t3d6/08B c21t3d6/14A c22t3d6/03B
0769 06DE c19t5d7/09A c20t5d7/08B c21t5d7/14A c22t5d7/03B
0769 06EE c19t6d1/09A c20t6d1/08B c21t6d1/14A c22t6d1/03B
0769 071E c19t6d7/09A c20t6d7/08B c21t6d7/14A c22t6d7/03B
0769 086E c19t12d1/09A c20t12d1/08B c21t12d1/14A c22t12d1/03B
0769 087E c19t12d3/09A c20t12d3/08B c21t12d3/14A c22t12d3/03B
0769 08AE c19t13d1/09A c20t13d1/08B c21t13d1/14A c22t13d1/03B
0769 0926 c24t14d6/14A c25t14d6/03B c26t14d6/08B c27t14d6/09A
0769 093E c24t15d1/14A c25t15d1/03B c26t15d1/08B c27t15d1/09A
0769 0A06 c24t2d0/14A c25t2d0/03B c26t2d0/08B c27t2d0/09A
0769 0A66 c24t3d4/14A c25t3d4/03B c26t3d4/08B c27t3d4/09A
0769 0A86 c24t4d0/14A c25t4d0/03B c26t4d0/08B c27t4d0/09A
0769 0AAE c24t4d5/14A c25t4d5/03B c26t4d5/08B c27t4d5/09A
0769 0AC6 c24t5d0/14A c25t5d0/03B c26t5d0/08B c27t5d0/09A
0769 0AD6 c24t5d2/14A c25t5d2/03B c26t5d2/08B c27t5d2/09A
0769 0C9E c24t12d3/14A c25t12d3/03B c26t12d3/08B c27t12d3/09A
0769 140E c41t1d1/08B c42t1d1/09A c43t1d1/14A c44t1d1/03B
0769 141E c41t1d2/08B c42t1d2/09A c43t1d2/14A c44t1d2/03B
0769 1426 c41t1d3/08B c42t1d3/09A c43t1d3/14A c44t1d3/03B
0769 1436 c41t1d4/08B c42t1d4/09A c43t1d4/14A c44t1d4/03B
----------------------------------------------
I need to filter all the devices ending with 'B' ( example: c9t3d3/08B ) and need to produce a single file with all the 'B' devices one after another in a column format.
The file attached to view in the proper format:
The output should be look like this:
c41t1d2/08B
c41t1d4/08B
c25t12d3/03B
c25t5d2/03B
...
Please suggest how to do it with the help of a script,
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2007 06:17 PM
11-02-2007 06:17 PM
Re: scripting question: Filtering certain fields and data. ?
Since your starting character is 'c' and ending is 'B' , you can do the following to get as you wanted.
cat filename |tr ' ' '\n' |grep '^c'|grep 'B$'
Regards,
RD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2007 06:20 PM
11-02-2007 06:20 PM
Re: scripting question: Filtering certain fields and data. ?
awk '
BEGIN { PAT = "B$" }
$3 ~ PAT { print $3 }
$4 ~ PAT { print $4 }
$5 ~ PAT { print $5 }
$6 ~ PAT { print $6 }
' filename
Is there any ordering requirements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2007 06:31 PM
11-02-2007 06:31 PM
Re: scripting question: Filtering certain fields and data. ?
note: there is a single space in the tr ...
cat filename |tr ' ' '\n' |grep '^c'|grep 'B$' > filename.out
Regards,
RD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2007 06:42 PM
11-02-2007 06:42 PM
Re: scripting question: Filtering certain fields and data. ?
This can be optimized to remove useless cats:
tr ' ' '\n' < filename | grep '^c.*B$'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2007 01:43 AM
11-03-2007 01:43 AM
Re: scripting question: Filtering certain fields and data. ?
$ perl -ne 'while (/\b(c\S+B)\b/) {print qq($1\n);$_=$'"'}" filename
This is a double loop, the -n looping over the records.
The a loop looking for:
\b = a word boundary
( = start remembering
c
\S+ a series of 1 or more non-whitespace
B
) = stop remembering
\b a word boundary
If matched, print the remembered part and make the default variable $_ become the 'post-match' remainder of the line.
The is expressed with $'
Of course the ' fights with the initial '
One way to solve that is a terminate the 'program' string and open a new "rest" string with the '. Ugly.
There are alternatives, and this problem does not exist for a program in a script. It is a command line thing.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2007 02:49 AM
11-03-2007 02:49 AM
Re: scripting question: Filtering certain fields and data. ?
Here's another (TMTOWTDI) Perl:
# perl -nle '{@a=split;print for /c\S+B/g}' file
...This splits each line on whitespace (spaces, tabs, newlines) and looks for strings beginning with a "c" and ending with "B" with at least one non-whitespace (\S+) character between. For every matching occurance on each line, the matched token is printed.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2007 03:15 AM
11-03-2007 03:15 AM
Re: scripting question: Filtering certain fields and data. ?
Ooops, ignore my first post. I posted a composite of two approaches without sufficient refinement. Instead, use:
# perl -nle '{print for /\bc\S+B\b/g}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2007 04:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2007 02:59 PM
11-05-2007 02:59 PM
Re: scripting question: Filtering certain fields and data. ?
I like all the scripts given here : tr, perl , awk and all worked fine. Though one perl script found to be long enough. And the best one found the oneliner one. Thanks all (again!).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2007 03:28 PM
11-05-2007 03:28 PM
Re: scripting question: Filtering certain fields and data. ?
The best one may be the one you can understand and perhaps modify. (That's why I had the 4 fields.)