- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep string from compressed file
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
03-06-2007 12:52 AM
03-06-2007 12:52 AM
I have created a 500mb file by concatenating lots of small files together:
file:abc.txt
data
data
data
:EOF
I have then compressed the file. What I would like to know is the command that can extract all the data between file:abc.txt and :EOF without uncompressing the file.
I have installed gnu.grep (zgrep) which can find the string in that file.
Thanks in advance.
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:04 AM
03-06-2007 01:04 AM
Re: grep string from compressed file
"cat"?
If so, I doubt that there are any file header indicators in the file - so all you could use to key off of for the end of abc.txt would be whatever the last piece of text is in abc.txt file.
Re; the second requirement of not uncompressing. Well you're going to have to uncompress either via your own code or some code from a program that understands the compression for that file - but you're going to have to uncompress.
UNLESS, you mean you don't want to uncompress to a file - you could uncompress to a pipe. Is that the question here, how to retrieve the 3 data files from a pipe which has uncompressed the file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:10 AM
03-06-2007 01:10 AM
Re: grep string from compressed file
# gzip -d -c file|perl -nle 'print if /abc.txt/../:EOF/'
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:12 AM
03-06-2007 01:12 AM
Re: grep string from compressed file
can't you use something like:
zgrep -v -e'^file:' -e'^:EOF' input > output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:12 AM
03-06-2007 01:12 AM
Re: grep string from compressed file
to create the files I ran a small script
for aa in `ls dir`
echo "file:$aa">>$outfile
cat $aa >> $outfile
echo ":EOR" >>$outfile
done
I will try gzcat.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 01:31 AM
03-06-2007 01:31 AM
Re: grep string from compressed file
I am playing with the gzip utility which works well to extract the string I require however the string is a unique number and will only appear once therefore once the string has been found then the search should stop.
here is what I require:
string to search is BGM001025176958
I need to recreate the file that was orginally on the server:
file:abc.txt
data
data
BGM001025176958
data
:EOR
so once the string has been identified then I want to create the file abc.txt containing
data
data
BGM001025176958
data
I have an idea howevr my awk syntax ain't quite correct.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 04:08 AM
03-06-2007 04:08 AM
Re: grep string from compressed file
Here is some awk that would do what you desire:
awk -F: '/BGM001025176958/{p=1} /^:EOR/ && (p) {while (i
C:\Temp>type abc.txt
file aaa.txt
data
BGM001025176958
data
With comments....
/BGM001025176958/{p=1} ## Desired pattern? Set print flag!
/^:EOR/ && (p) ## Line starting with end mark? Also have print flag set? then...
{while (i
exit} ## and done
{a[n++]=$0}' ## Remember every line in its own place.
/^file:/ {name=$2; n=0} ## Line starting with new file? remember name part and reset number of lines.
Enjoy!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 11:41 PM
03-06-2007 11:41 PM
Re: grep string from compressed file
any other idea's?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2007 11:55 PM
03-06-2007 11:55 PM
Re: grep string from compressed file
I got an error message showing the problem:
awk: A print or getline function must have a file name.
I then initialized name to "bad_news" and got the output.
The problem is an extra space after the "e" in file. I fixed it here:
/^file/{name=$2; n=0}
It might be easier to read as:
awk -F: '
BEGIN { name="bad_news" }
/BGM001025176958/{p=1}
/^:EOR/ && (p) {while (i
{a[n++]=$0}
/^file/{name=$2; n=0}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2007 12:02 AM
03-07-2007 12:02 AM
Re: grep string from compressed file
Ooops, like Dennis indicates i made a cut & paste error. I tried it on a Windoze box and the awk had trouble with specifying a ":" as field seperator. So I changed the data to use spaces, for the test replacing them in the posted string.. except for the /^file:/ match. Sorry.
And, You need to feed (pipe) it the input stream of course,
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2007 12:04 AM
03-07-2007 12:04 AM
Re: grep string from compressed file
Thanks guys.
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2007 12:40 AM
03-07-2007 12:40 AM