- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Removing constant pattern and whitespaces.
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-08-2002 12:21 AM
07-08-2002 12:21 AM
I would like to remove every instance of the following pattern:
.output
=============
from the file attached. This pattern is a subset of the pattern:
pglc0003.output
=============
As there are whitespaces separating each entries, how do I write a script to eliminate those whitespaces and at the same time remove the mentioned pattern?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 12:32 AM
07-08-2002 12:32 AM
Re: Removing constant pattern and whitespaces.
cat file|while read line
do
echo |sed -e 's/.output//'|grep -v "======="
done|strings > newfile
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:02 AM
07-08-2002 01:02 AM
SolutionThis small script will help you.
...............................
#!/usr/contrib/bin/perl -w
while(
s/^\s*$//;
s/\.output//;
print;
}
...............................
run this script as $ cat text_file | script
or
$ script < text file.
HTH,
Karvendhan M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:18 AM
07-08-2002 01:18 AM
Re: Removing constant pattern and whitespaces.
I missed the === .. pattern.
the script can be
----------------------------------
#!/usr/contrib/bin/perl -w
while(
s/^\s*$//; # remove blank lines.
s/^\=+\s*$//; # Remove === ..
s/\.output//; # Remove .output.
s/^\s+//; # remove leading space in lines.
print;
}
------------------------
~ Karvendhan M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:30 AM
07-08-2002 01:30 AM
Re: Removing constant pattern and whitespaces.
while read $a
basename $a .output
done
# to remove ================
cat tmpfile1 |tr -s "=" >tmpfile2
# to remove whitespaces
cat tmpfile2 |tr -s " " >tmpfile3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:32 AM
07-08-2002 01:32 AM
Re: Removing constant pattern and whitespaces.
I forgot "do".
While read $a do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:34 AM
07-08-2002 01:34 AM
Re: Removing constant pattern and whitespaces.
I tried running your code exactly as you've shown me:
cat filename|while read line
do
echo |sed -e 's/.output//'|grep -v "====="
done|strings > newfile.txt
However, the file "newfile" does not contain any outputs.
Could you help me out?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:37 AM
07-08-2002 01:37 AM
Re: Removing constant pattern and whitespaces.
Steve's script should be....
echo $line |sed -e 's/ .....
HTH,
Karvendhan M
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 01:57 AM
07-08-2002 01:57 AM
Re: Removing constant pattern and whitespaces.
the line sed -e 's/.output//'|grep -v "===="
should remove the .output pattern followin the patterns pglc.., right?
Unfortunately, it's printing :
pglc0002.output
....
for all of its output.
Could you please help me out?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2002 06:13 PM
07-08-2002 06:13 PM
Re: Removing constant pattern and whitespaces.
pglc0000
pglc0001
etc.
I'd tend to use:
grep '[a-zA-Z]' | cut -f1 -d. > output.txt
I can think of other ways using sed etc. but this would be quicker
Cheers
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2002 07:24 AM
07-09-2002 07:24 AM
Re: Removing constant pattern and whitespaces.
Try Steve's script again, just modify the > newfile.txt to >> newfile.txt
ME
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2002 01:11 PM
07-09-2002 01:11 PM
Re: Removing constant pattern and whitespaces.
if you want the output to be :
pglc0000
pglc0001
etc.
I'd tend to use:
grep '[a-zA-Z]' | cut -f1 -d. > output.txt
I can think of other ways using sed etc. but this would be quicker
Cheers
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2002 02:15 PM
07-09-2002 02:15 PM
Re: Removing constant pattern and whitespaces.
pglc0003
pglc0004
pglc0005
etc.
Use:
cat yourfile | grep output | sed s/\.output//g > newfile