LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-08-2015, 05:49 AM   #1
sivanenu
LQ Newbie
 
Registered: May 2015
Posts: 2

Rep: Reputation: Disabled
how to extract data between a matched strings in a file


Hi All,
I got stuck when i am trying to extract the data between a matched strings in a file which contains a million records with \t is the field seperator. i am getting that matched_string in only one particular field(5 field).

ex: fiel_name:siva.txt

record_1: a b c d _bb_vid:dfndjgddgn~~~ e f g
record_2: h g e f _bb_vid:kdjgfkdhjk~~~ k h d

like this lakhs of records will be there. i want add the result set into end of the file with \t as field seperator.

estimated_out_put:
record_1: a b c d _bb_vid:dfndjgddgn~~~ e f g dfndjgddgn
record_2: h g e f _bb_vid:kdjgfkdhjk~~~ k h d kdjgfkdhjk

please help me guys.
 
Old 05-08-2015, 07:26 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You use awk script to do that. Each field would be variable. So you put the field again in the end.

Read more about awk by 'info awk'.
 
Old 05-08-2015, 11:18 AM   #3
sivanenu
LQ Newbie
 
Registered: May 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
will you please elaborate with an example. i am new to linux.
 
Old 05-08-2015, 11:59 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,477

Rep: Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970Reputation: 3970
Quote:
Originally Posted by sivanenu View Post
will you please elaborate with an example. i am new to linux.
Please read the "Question Guidelines" link in my posting signature.

You can VERY EASILY find many awk examples (as well as examples using other tools), if you tried a brief Google search for something very obvious, like "how to get data between two strings in linux". We are happy to help you, but you are going to have to show some effort of your own. Post what you've done/tried, or post one of the examples you found and tell us what you're confused about. But we aren't going to look things up for you.
 
Old 05-08-2015, 12:01 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
awk manual

You will need to look at the FS (field separator) variable, would suggest setting to : and ~

Then simply append a tab and the appropriate field to the end of the line (referenced by $0)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Extract info and find/count strings from blocks inside text file Alkass Programming 6 01-24-2015 12:26 PM
Extract info and find/count strings from blocks inside text file Alkass Linux - Newbie 1 01-24-2015 11:16 AM
Extract data from a file using bash then use part of that data to rename the input fi mfarch99 Linux - Newbie 11 09-05-2014 10:51 AM
How to take the data from a strings in a file and output them as the HTML using perl vesskrishna Linux - Newbie 3 11-22-2011 03:20 AM
gnuplot: how to label x-axis with strings from data file? hedpe Linux - Software 2 07-11-2006 10:21 AM


All times are GMT -5. The time now is 02:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration