Need help get particular pattern from a file content!!
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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#
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#
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/'
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#
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.