- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep one line + one line more is possible??
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
06-21-2004 07:06 PM
06-21-2004 07:06 PM
I would like to grep one word in one file, and I have to take this line and the line after... If its possible with grep??... if not is it possibe with another command??
Exemple
If I have this text in a file:
Completed: ALTER DATABASE DATAFILE '/oracle/BUGD02/oradata1/B
Wed Nov 19 18:29:44 2003
Thread 1 advanced to log sequence 2
Current log# 2 seq# 2 mem# 0: /oracle/BUGD02/oradata1/BUGD02/logBUGD02_2.dbl
Wed Nov 19 18:31:07 2003
Thread 1 advanced to log sequence 3
Current log# 3 seq# 3 mem# 0: /oracle/BUGD02/oradata1/BUGD02/logBUGD02_3.dbl
(.....)
Wed Nov 19 18:35:07 2003
Completed: CREATE TABLESPACE RBS DATAFILE '/oracle/BUGD02/ora
Wed Nov 19 18:35:07 2003
I would like to take only the line with Completed and the line with de date.
Thanks!
Carmen.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 07:14 PM
06-21-2004 07:14 PM
Re: grep one line + one line more is possible??
may look a bit complicated, but is should work
awk '/(^Completed)|(^Mon) | (^Tue) | (^Wed) | (^Thu) | (^Fri) | (^Sat) | (^Sun)/ {print $0}' filename
with best wishes
Naveej
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 07:16 PM
06-21-2004 07:16 PM
Re: grep one line + one line more is possible??
You can get GNU grep here
http://hpux.connect.org.uk/hppd/hpux/Gnu/grep-2.5.1/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 07:23 PM
06-21-2004 07:23 PM
Re: grep one line + one line more is possible??
This only shows lines whith Completed and Mon.... ¿?
Completed: ALTER DATABASE CLOSE NORMAL
Mon Apr 26 00:10:55 2004
Completed: ALTER DATABASE DISMOUNT
Mon Apr 26 03:53:58 2004
Mon Apr 26 03:54:02 2004
Mon Apr 26 03:54:07 2004
But I only need lines with 1) Completed and 2) the date....
If there are more lines with Completed or dates in the middle I would like ignore it.
If it possible with awk??
Thanks!
Carme
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 07:24 PM
06-21-2004 07:24 PM
Solutionperl -ne '/text to match/ || next;print $_;$_=<>;print' datafile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 08:51 PM
06-21-2004 08:51 PM
Re: grep one line + one line more is possible??
I use a script to get all errors in the alert*.log and the "lines around", i.e. 2 before and 5 after without getting duplicated lines - for what it's worth - :
grep -n '^ORA' $PATH/$ALERT_FILE | while read line
do
expr $line - 2 | read before
expr $line + 5 | read after
if [ $last -lt $before ] ; then
printf "%d,%dp\n" $before $after >> $SED_SCRIPT
else
printf "%d,%dp\n" `expr $last + 1` $after >> $SED_SCRIPT
fi
last=$after
expr $line + 1 | read after
printf "%d,%dp\n" $line $after >> $SED_SCRIPT
done
sed -nf $SED_SCRIPT $ALERTE_FILE
Change it to suit your need (^ORA --> ^Completed ; ....)
Cheers
Nicolas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 09:00 PM
06-21-2004 09:00 PM
Re: grep one line + one line more is possible??
what about this one:
# cat filename | egrep 'Completed|Mon|Tues|Wed|Thur|Fri|Sat|Sun'
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 09:04 PM
06-21-2004 09:04 PM
Re: grep one line + one line more is possible??
I did just notice that my perl thing above will hang if it matches something in the last line of the file because it tries to read the next line.
This change stops that happening
perl -ne '/text to match/ || next;print $_;if(not eof){$_=<>;print}' datafile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2004 09:08 PM
06-21-2004 09:08 PM
Re: grep one line + one line more is possible??
See if this one is useful..
#!/usr/bin/ksh
list=`cat file1 | cut -d " " -f 1`
echo " Enter file name to search patterns \n"
read VAR2
myfunct()
{
while true
do
VAR1=$1
if [ $# -gt 0 ]
then
for VAR1 in Mon Wed Tues Fri Sat Sun Completed
do
cat $VAR2 | grep "$VAR1"
done
shift
else
exit
fi
done
}
myfunct $list
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 10:42 PM
06-22-2004 10:42 PM
Re: grep one line + one line more is possible??
Try this: sed -n '/^Completed: /{N;p;}'
Regards
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2004 11:33 PM
06-22-2004 11:33 PM
Re: grep one line + one line more is possible??
(though sometimes the lines can be quite long!!)
cat logfile | sed -n -e '/^Completed/{N;p;}'
Regards
Alan Mason