LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-02-2012, 06:54 AM   #1
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Rep: Reputation: 1
Question Need help get particular pattern from a file content!!


Hi all,

I want to get specific pattern from a file content. grep is not working.

file content as follows:
^F^Cã^CÜ^C¾^C·^C\231^C\2226440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-in


I am interested for the pattern "6440569" only.
 
Old 05-02-2012, 07:00 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Assuming that 6440569 is just an example and can be any number, have a look at this:
Code:
sed 's/.*event-id-old\(.*\)gps-input-channel.*/\1/' infile
Hope this helps.
 
Old 05-02-2012, 07:04 AM   #3
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
actually file content some binary/other character as well and the occurence of this sctring is twice:

^F^Cã^CÜ^C¾^C·^C\231^C\2226440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-in
 
Old 05-02-2012, 07:11 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by vaibhavs17 View Post
actually file content some binary/other character as well
What kind of file is it? Post the output of the following command:
Code:
file infile
Quote:
the occurence of this sctring is twice:

^F^Cã^CÜ^C¾^C·^C\231^C\2226440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-in
What are you trying to tell me? If they are the same do you want/need them to be shown twice?

Does my provided example show what you need (be it just once)?

Please be a precise as possible when you describe your problem, give a relevant example of the input file and an example of what you want as output.

Hope this helps.
 
Old 05-02-2012, 07:28 AM   #5
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
trmusprv:/data/apps/tradem/trmusprv/gps/state# file gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag: data


I tried your command but some how getting error

trmusprv:/data/apps/tradem/trmusprv/gps/state# sed 's/.*event-id-old\(.*\)gps-input-channel.*/\6440569/' gps-state-Pvst_US_Sub_GoodRaw_Delim_19.p
ag
sed: command garbled: s/.*event-id-old\(.*\)gps-input-channel.*/\6440569/trmusprv:/data/apps/tradem/trmusprv/gps/state#

I want to show this once.

thanks for your help on this
 
Old 05-02-2012, 07:31 AM   #6
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
I tried this as well

trmusprv:/data/apps/tradem/trmusprv/gps/state# sed 's/.*event-id-old\(.*\)gps-input-channel.*/\1/' gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
trmusprv:/data/apps/tradem/trmusprv/gps/state#


no output
 
Old 05-02-2012, 07:39 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by vaibhavs17 View Post
trmusprv:/data/apps/tradem/trmusprv/gps/state# file gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag: data
If this is a partial binary data file then extracting the wanted string might become problematic. Tools like awk, grep and sed work on text files, not binary/data files.

You can try the following:
Code:
strings infile | sed 's///'
The sed part is a dummy example, without knowing what strings infile spits out I can't give a working sed statement.

If I would assume that the string command outputs something like this: 2226440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-in, then the following should work;
Code:
strings infile | sed 's/.*event-id-old\(.*\)gps-input-channel.*/\1/'
or simpler:
Code:
strings infile | sed 's/\(.*\)gps-input-channel.*/\1/'
Hope this helps.
 
Old 05-02-2012, 07:47 AM   #8
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
No output

trmusprv:/data/apps/tradem/trmusprv/gps/state# strings gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag | sed 's/\(.*\)gps-input-channel.*/\1/'
trmusprv:/data/apps/tradem/trmusprv/gps/state#


No output
trmusprv:/data/apps/tradem/trmusprv/gps/state# strings gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag | sed 's/.*event-id-old\(.*\)gps-input-channel
.*/\1/'
trmusprv:/data/apps/tradem/trmusprv/gps/state#
 
Old 05-02-2012, 07:56 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Instead of telling us there is no output, you might want to post a relevant part of
Code:
strings gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
As stated before: The sed part is a dummy example, without knowing what strings infile spits out I can't give a working sed statement.

Last edited by druuna; 05-02-2012 at 07:58 AM. Reason: Fixed tags.
 
Old 05-02-2012, 08:26 AM   #10
vaibhavs17
Member
 
Registered: Mar 2009
Posts: 51

Original Poster
Rep: Reputation: 1
trmusprv:/data/apps/tradem/trmusprv/gps/state# strings gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
trmusprv:/data/apps/tradem/trmusprv/gps/state#


trmusprv:/data/apps/tradem/trmusprv/gps/state# cat gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
ãܾ·6440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-intrmusprv:/data/apps/tradem/trmusprv/gps/state#


^F^Cã^CÜ^C¾^C·^C\231^C\2226440569gps-input-channel-event-id-out6440568gps-input-channel-event-id-old6440569gps-input-channel-event-id-in
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag" [Read only] [Incomplete last line] 1 line, 1024 characters (901 null)
 
Old 05-02-2012, 09:55 AM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by vaibhavs17 View Post
trmusprv:/data/apps/tradem/trmusprv/gps/state# strings gps-state-Pvst_US_Sub_GoodRaw_Delim_19.pag
trmusprv:/data/apps/tradem/trmusprv/gps/state#
If not output is generated by using strings then I guess you are out of luck when it comes to the majority of the linux tools, which work with text files and not with data/binary files.

I'm sure C/C++ (higher level programming language) can do this, but I cannot help you with that (besides that: you would also need to know the ins and outs of the generated *.pag files to write a program). Maybe someone else reads this thread and is able to help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] replace matched pattern from 1st file into 2nd file using awk sopier Programming 6 12-13-2011 09:58 AM
Dividing content of one file by content of another larspend Linux - Newbie 5 04-12-2011 08:00 PM
[SOLVED] How to replace newline pattern in file by other newline pattern in a shell script XXLRay Linux - Software 9 11-29-2010 07:57 AM
PERL pattern matching while reading a file content is dead slow gaynut Programming 13 08-13-2008 06:59 AM
renaming text files based upon a pattern in their content Spacepup Linux - General 1 07-28-2005 01:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration