LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 12-21-2014, 11:12 PM   #1
snehasishmohanta
LQ Newbie
 
Registered: Dec 2014
Posts: 2

Rep: Reputation: Disabled
Red face regarding pattern


As i am new to ubuntu i stuck in a place. how can i get a particular pattern from my terminal and can save to any file like .txt file or any libre office file. file looks like:-
Quote:
[Dec 17 00:00:07] [302134] [snapdeal-suggest] [info] - Initial query: lg e975
[Dec 17 00:00:07] [302134] [snapdeal-suggest] [info] - Input query: lg, Spell-corrected query: lg e975, NumSuggestions: 0, Time taken: 70 microseconds


and i want to save this in following format:
Quote:
TIME STAND----------Initial query---------NumSuggestions
[Dec 17 00:00:07]------lg e975-------------------0

Last edited by snehasishmohanta; 12-21-2014 at 11:14 PM.
 
Old 12-23-2014, 07:42 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Welcome to LQ snehasishmohanta!

Unfortunately I do not get what you want. Parse a text file or some output of a command?
 
Old 12-23-2014, 10:28 AM   #3
JimKyle
Member
 
Registered: Dec 2001
Location: Oklahoma City, OK, USA
Distribution: Xubuntu 16.04 LTS
Posts: 214
Blog Entries: 1

Rep: Reputation: 39
If I'm comprehending your question correctly, it appears that "awk" would be a great solution for you. Its learning curve is a bit steep and it appears to be more of a programming language than folks today like, but it was developed back in the early days of Unix itself for exactly the purpose you propose.

AWK is a pattern-matching script language that parses each line received from STDIN (or from a file) according to matching rules that you provide, and upon finding a match, performs actions that you specify. These actions can provide output to STDOUT (or, again, to a file), or can simply move on to the next line of input. All details of the parsing itself are hidden behind the scenes. The strange name comes from the initials of the three pioneers at Bell Labs who created it: Aho, Weinberger, and Kernighan. They later wrote an entire book explaining its use; you might find it on the web, still.

This is only a rough overview of AWK's capabilities; Google for "awk" to find many more leads than you're likely to need. The "man" pages for it, like most man pages, tend to be somewhat cryptic and assume advanced knowledge, but there are several good tutorials and how-tos out there that can get you started, in addition to the original book.

I've used it for more than a decade now. Once you create your script and get it working, you simply call it from the command line and your jobs are done. Biggest time saver I've found -- and I'm one of the laziest computer users you'll ever encounter.

If you run into trouble with it, I'll be happy to try to help. But I think you'll find it fairly easy to learn. Hope this helps!

Last edited by JimKyle; 12-23-2014 at 10:31 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and replace Pattern preceeding another pattern nbkisnz Programming 3 05-13-2012 01:50 PM
[SOLVED] /bin/bash if statement pattern search, end of pattern special character? headhunter_unit23 Programming 3 04-29-2010 08:05 AM
[SOLVED] Adding (not replacing) a pattern match with a similar pattern? b-bri Linux - Newbie 2 08-31-2009 12:36 AM
substituting pattern only if another pattern is present rattlesnakejoe Programming 4 07-22-2009 07:46 PM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 06:22 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