- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Read text file from a specified string to the ...
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
тАО01-08-2008 06:27 PM
тАО01-08-2008 06:27 PM
Read text file from a specified string to the end of the file.
I like to read the log file from specific time to end of the file.
eg:
message0
date and time0
message 1
date and time1
message 2
EOF
I want to read all the text (Messages) after date and time0 to end of the file.
Please let me know the UNIX command to perform this?.
Thanks,
bsraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:03 PM
тАО01-08-2008 07:03 PM
Re: Read text file from a specified string to the end of the file.
It can be done in many, many ways (Sed, Perl,
Awk, and so on). I am sure our colleagues
in the Forum will flood you with responses :)
Since I am on holidays (sigh, why am I
then still logging infor HP Forums :)),
here are two simple methods in Awk (I am not
sure which version of Awk you use):
awk '/date and time0/,EOF {getline;print}'
or
awk /date and time0/,0 {getline;print}'
Cheers from sunny and hot Sydney - Australia,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:25 PM
тАО01-08-2008 07:25 PM
Re: Read text file from a specified string to the end of the file.
Thanks for your response.
I am trying to read the log file (from the specified data and time ) using my K-Shell script and i am creating a new temp file with only the contents after the specified date and time.
Thanks,
bsraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 07:55 PM
тАО01-08-2008 07:55 PM
Re: Read text file from a specified string to the end of the file.
That is fine.
You simply put the folloiwiung line in your Ksh script. Sometjhing along the followiung line:
#!/bin/ksh
PATH=/usr/bin:/sbin:/bin
export PATH
INPUTLOG="/somedir/mylogfile.txt"
OUTFILE="someotherdir/results.txt"
if [ -s "$INPUTFILE" ]
then
awk '/date and time0/,EOF {getline;print}' $INPUTFILE >$OUTFILE
if [ $? -ne 0 ]
then
echo "WARNING: Command awk failed"
exit 1
fi
fi
exit 0
If you are happy with the solution please do
not forget to assign points before closing the thread :)
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 08:42 PM
тАО01-08-2008 08:42 PM
Re: Read text file from a specified string to the end of the file.
I appreciate your help, but again I am having some issues.
I am getting the following error
awk: syntax error near line 1
awk: bailing out near 1
and I am not sure this is because of the spaces in between the date and time.
Please find my sample code.
#! /bin/ksh
set -x
LogFile="/tmp/scan_log.log"
LoadFile="/tmp/new_scan_log.log"
Last_Alert="Alert: Fri Jan 4 16:15:01 2008"
if [ -s "$LogFile" ]
then
awk '/$Last_Alert/,EOF {getline;print}' $LogFile >> $LoadFile
fi
exit 0
Thanks,
bsraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-08-2008 09:04 PM
тАО01-08-2008 09:04 PM
Re: Read text file from a specified string to the end of the file.
You awk line does not escape the search string.
Try this:
awk '/'"$Last_Alert"'/,EOF {getline;print}' $LogFile >> $LoadFile
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 03:40 AM
тАО01-09-2008 03:40 AM
Re: Read text file from a specified string to the end of the file.
I'm not sure why you have EOF? It seems this is just the empty string. Also your getline causes it to skip every other line.
If you want to start from your $Last_Alert you can use sed:
$ sed -n "/$Last_Alert,$/p" $LogFile >> $LoadFile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 03:51 AM
тАО01-09-2008 03:51 AM
Re: Read text file from a specified string to the end of the file.
# print section of file from regular expression to end of file
sed -n '/regexp/,$p'
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 07:19 PM
тАО01-09-2008 07:19 PM
Re: Read text file from a specified string to the end of the file.
Dennis is right: getline is not needed as
it prints every second line only.
This works 100%:
awk '/'"$Last_Alert"'/,EOF {print}' $LogFile >> $LoadFile
You need "EOF" or "0" string because
otherwise you only get a matching line.
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-10-2008 09:02 PM
тАО01-10-2008 09:02 PM
Re: Read text file from a specified string to the end of the file.
Thanks for all your details. I am still getting the same error when using the awk command, but using the below command i am able to list all the details..
sed -n "/^$Last_Alert/,$ p" $LogFile >> $LoadFile.
But the above command is listing including the specified string.
Please let me is there any way to list the error messages after the specified date and time. (Thu Jan 10 12:56:50 2008)
eg:
Thu Jan 10 12:56:49 2008
err0
Thu Jan 10 12:56:50 2008
err1
Thu Jan 10 12:56:51 2008
err2
if Last_Alert = Thu Jan 10 12:56:50 2008 then, the next time i like to list all the errors only after that.
eg
Thu Jan 10 12:56:51 2008
err2
Thanks,
bsraj.