1- First of all I am not a student and this is not a homework
2- I run some programs that give outputs in the format as I mentioned above. The datas must be ordered to plot some graphics and figures.
3- I have tried awk commands because I have been trying to learn it and now I am familiar to awk.
4- I have tried following command types but they didnt work
awk '/^person/{next}/ ' myfile > myfile2
#awk '/^======/{next}/^(person|19)/{out=$1".txt";next}{print >out}' a > a1
---------- Post updated at 09:20 PM ---------- Previous update was at 08:44 PM ----------
bartus11 I tried to apply your command to my script but it didnt work. The exact form of my data as fllows. Which parameter must be changed in your previous command line ???
r-point 1 : 0.0000
band No. DT-energies P-energies
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi, rpf.
I'll let bartus11 explain his code.
I think you were close on your tries.
A very simple code:
this simply looks for string person and increases the counter of which the output file name will be made. It doesn't care about the string inside the ( ... ).
Another code that will extract that string and use it as part of the filename:
This deletes the strings before and after the string inside the parentheses so that
will become just something, which will become part of the output filename.
I hope you will continue to learn about awk, it is a very useful tool.
However, if another command already exists to perform a task, then it is reinventing the wheel to write something specific in awk (or perl or c or ... )
My source file is structured with two words on each line
word1 word2
word1 word2
I am using sed and awk to grab groups of specific lines
line=`awk 'NR>=4 && NR<=7' file1`; echo $line
line=` sed -n '1,5'p file1`; echo $line
The resulting output is
word1 word2 word1 word2 word1... (1 Reply)
Hello,
I was wondering how is it possible if I use this command:
awk 'NR >= 998 && NR <= 1000' file.txtTo exit after parsing the 1000th line ( last line targeted) ???
I observed that when executing this command for a large file, if the range of lines is at the beginning of the file it is... (2 Replies)
Hi guys!
I'm new to scripting and I need to write a script in awk.
Here is example of file on which I'm working
ATOM 4688 HG1 PRO A 322 18.080 59.680 137.020 1.00 0.00
ATOM 4689 HG2 PRO A 322 18.850 61.220 137.010 1.00 0.00
ATOM 4690 CD ... (18 Replies)
Hi,
I have one file, say file 1, that has data like below where 19900107 is the date,
19900107 12 144 129 0.7380047
19900108 12 168 129 0.3149017
19900109 12 192 129 3.2766666E-02
... (3 Replies)
Hi,
We have a file where we need to extract the lines of a file based on the first three characters of every line in that file.
Eg:
RAM hill station
SAM student
RAM rose
SAM apple
RAM india
SAM australia
RAM happy
RAM heaven
SAM smile
RAM glow
So, all the lines that start... (5 Replies)
Hi All,
I would like to extract from a text file m lines skipping n lines after a string occurrency. Is it possible with grep?
e.g.
qqq
ww
eee
rrr
ttt
yyy
uuu
I want to print 2 lines skipping 1 line after the string 'ww'
result would be
rrr
ttt (2 Replies)
Hi All,
I am trying to extract lines bsed on pattern matching../mp straight-flow/
Extracted output should be saved in meta_string , but the code is not working in that manner,saving repeated lines. can anyone please suggest where am i going wrong.
/mp straight-flow/ {... (6 Replies)
i want to extract lines 5 and 7 from a txt file which contains nearly 20 entries how to do it
also i want to check whether the 42nd character is 'S' in that line
suggestions welcome (4 Replies)
Hi all,
I need to extract some lines from a file based on a condition. For ex:
My file will contain 50 lines and i need to extract line which has "File" in it and then the line which has "date" in it. Which command will be the most efficient way to do it. I have tried two ways
1.... (1 Reply)