Read n lines from a text files getting n from within the text file
I dont even have a sample script cause I dont know where to start from. My data lookes like this
and so on. I need the sript to read the first line with text and use the #data value to determine how many lines to read below this text line, then read those lines of data, then read the next line with text and use the #data value to count how namy lines to read below that and so on.
To be honext I have no idea where to start from. And honestly I am not completely new to shell scripting but this has challenged me to the core. This is not an assignment, its for my rresearch work am a seniour lecturer in the department of physics at the university of zambia in lusaka, zambia. I hope it is doable.
The read data can be directed to a gnuplot ot output to a file.
Note that there are only 14 lines following the 1st line, but the 1st line contains #data: 15; is a line missing in your sample, or is the XXX value in the #data: XXX segments of the headers unreliable? (Note that since the header lines all start with a ">" and the data lines only contain floaing point values, the count in the header can be ignored.)
The counts in the other two header lines seem to match the following data.
Once you have read the data lines, what do you want to do with them?
Good points Don Cragun, my assumption was that the value in the data line was less than then number of lines and any additional lines need to be discarded.
In my solution, any processing could be done in the NR <=R block:
Good points Don Cragun, my assumption was that the value in the data line was less than then number of lines and any additional lines need to be discarded.
In my solution, any processing could be done in the NR <=R block:
Understood.
The O.P. said the output "can be directed to a gnuplot ot (sic) output to a file.", but didn't specify any options for gnuplot and didn't specify filenames nor whether the headers should be included in the files or stripped from the files. There is no gnuplot man page in the Man Pages section of this forum, but some references I found said that it is very picky about having its input in tab separated fields (and the data lines given in the sample input have no tabs). Should all data be sent to one instantiation of gnuplot or should the data under each header be sent to a different instantiation of gnuplot?
I don't think I can do much more until we get a clarification on the requirements.
Thank you vry much for all your advices, I am now working on ta script to use this method and I will report back just now to let you know the result. I want to plot the data once I have read it. and since I want to plot in different colors, for each block so I will direct my output to a gnuplot script, I hope that works.
I will let you know the result!
Thank you
---------- Post updated at 08:30 AM ---------- Previous update was at 07:17 AM ----------
Good afternoon,
Somehow I am not able to get this to do what I want to do.
I am trying to do is to read the value after #data, that should be the number of data lines in that block, so I should be able to read that number of lines under that header and sent that to a file which I will then call in gnuplot and plot that particular data.
The Final output is a plot of column 1 vs column 7 all the blocks on the same plot. But since the column 1 is not in a continuous sequence, I need to plot each block of data separately and overplot on the same plot.
Here is the intedend output
Either the data for each block is sent to a seperate file like this
file 1
file 2
file 3
so that I can then use gnuplot to plot column 1 vs colomn 7 for each file on the same plot.
If instead of sending the data to a file I can send it directly to gnuplot and produce one plot with lines for each block of data then that would be the perfect result I am looking for.
For example I have put this line into a script
I expected that data.out should contain the data but without the headers for each block and thats not what is happening.
Thank you all the the time and assistance.... its much appreciated.
Regards
---------- Post updated at 08:35 AM ---------- Previous update was at 08:30 AM ----------
Sorry the output data didnt come out correctly in my post above here is the disired outpot
I repeat: "Note that there are only 14 lines following the 1st line, but the 1st line contains #data: 15 ;". The script you're using assumes that the 15 in the 1st line of your input file is correct and your output is wrong because that 15 should be 14 for the data in your input file.
If your input data is invalid, you will not get valid output. Or more commonly: GIGO (Garbage in; garbage out).
You can get the output you said want from that input with the following awk script (although I STRONGLY suggest that you not put a space in your filenames):
This User Gave Thanks to Don Cragun For This Post:
hi all,
trying this using shell/bash with sed/awk/grep
I have two files, one containing one column, the other containing multiple columns (comma delimited).
file1.txt
abc12345
def12345
ghi54321
...
file2.txt
abc1,text1,texta
abc,text2,textb
def123,text3,textc
gh,text4,textd... (6 Replies)
Hi,
I have a huge file that has data something like shown below:
huge_file.txt
start regexp
Name=Name1
Title=Analyst
Address=Address1
Department=Finance
end regexp
some text
some text
start regexp
Name=Name2
Title=Controller
Address=Address2
Department=Finance
end regexp (7 Replies)
Hello,
I have a file ff.txt that looks as follows
*ABNA.txt
356
24
36
112
*AC24.txt
457
458
321
2
ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Hello I'm having a little difficulty in writing a shell script for a few simple tasks.
First I have two files "file1.txt" and "file2.txt" and I want to read and compare the last line of each file. The files look like this.
File1.txt
File2.txt
After comparing the two lines I would... (2 Replies)
Hi,
I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN ... (2 Replies)
hi all,
I have this file with some user data.
example:
$cat myfile.txt
FName|LName|Gender|Company|Branch|Bday|Salary|Age
aaaa|bbbb|male|cccc|dddd|19900814|15000|20|
eeee|asdg|male|gggg|ksgu|19911216|||
aara|bdbm|male|kkkk|acke|19931018||23|
asad|kfjg|male|kkkc|gkgg|19921213|14000|24|... (4 Replies)
Witam wszystkich ,
Jest to moj pierwszy post i już prośba ale gdybym potrafił zaradzić problemowi to nie zawracałbym nikomu głowy .
mianowicie :
Mam jakis 'plik' w ktorym są osadzone pojedyncze i zmienne słowa po jednym w lini czyli :
test1
tekttw
resst
.... itd.
Moje... (6 Replies)
I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)