0

I have a data file with lots of value in a single file. I need to extract the data in between name 1 and name 2. I need a loop so that I can extract and save data in between using name1.dat, name2.dat and so on.

My file looks like :

name        1
data......
name        2
data.....

and so on.

I need to extract data between name 1 and name 2.

I have did

for i in 1 2; do awk '$1=="name" and $2=="'$i'" 

but I am stuck. How can I print in between?

  • Hi, In this question i need to save each data to its name. the question is not all the data between the pattern into a single file. i have name 1 to name 200. i will get name1.dat ...name200.dat file. – user2451501 Sep 16 '14 at 16:00
  • Try `awk '/name/{file=$1 $2 ".dat";next}{print > (file)}' file` – jaypal singh Sep 16 '14 at 16:58
  • This is not working. I have a file file.dat and it consist of data inside "name 1" is a pattern and end pattern could be before the line of "name 2 ". name is in first column and 1 is on second column. I need the save the data in between name 1 and name 2 as name1.dat and between name 2 and name 3 as name2.dat. – user2451501 Sep 17 '14 at 09:43

0 Answers0