LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to extract data between a matched strings in a file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-extract-data-between-a-matched-strings-in-a-file-4175541959/)

sivanenu 05-08-2015 05:49 AM

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.

veerain 05-08-2015 07:26 AM

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'.

sivanenu 05-08-2015 11:18 AM

will you please elaborate with an example. i am new to linux.

TB0ne 05-08-2015 11:59 AM

Quote:

Originally Posted by sivanenu (Post 5359672)
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.

grail 05-08-2015 12:01 PM

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)


All times are GMT -5. The time now is 09:25 PM.