Advise on how to print range of lines above and below a number?
Hi,
I have attached an output file which is some kind of database file mapping. It is basically like an allocation mapping of a tablespace and its datafile/s.
I have modified and rename the content but just mainly the segment name, I have put some segment name as an example.
In this example, the tablespace name is ABC_XYZXYZ_TXT and it is composed of two datafiles, file 18 and file 14. I am guessing Block 1 is the file header of each datafile hence the segment column is empty for where it is Block 1.
I'll try my best to explain what I am wanting to do. Before I go write a long script for it, I want to know first if maybe I can 'simply' use awk inside the script to search and print a range of lines above and below a given number.
For example, if I do x.ksh 3000, the script should print out something like below based on what's on testfile.txt.
At the moment, I am thinking of reading the file one at a time and comparing the third field to the given argument that is 3000. While it seem easy to print the next 5 records > 3000, I can't think of a way of saving the last 5 that are less than 3000?
I am hoping I can get some advice on how to achieve what I am wanting to do.
I have a few to questions pose in response first:-
Is this homework/assignment? There are specific forums for these.
What have you tried so far?
What output/errors do you get?
What OS and version are you using?
What are your preferred tools? (C, shell, perl, awk, etc.)
What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?
I'm not too clear what you intention is, but if you can numerically sort the data (or it already is) and pass it through grep, the -A and/or -B flags may do what you want.
There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.
Hi newbie_01,
Until you answer Robin's question about homework, you won't get any further help on this topic. And, with over 200 posts and more than 8 years in this forum, we shouldn't have to repeat the questions that Robin asked. We are happy to help you learn how to use UNIX utilities to do what you need to do, but we are not your unpaid programming staff. Other than needing to use line 2 in your input file to figure out where field boundaries are located, this is can be done with a pretty simple awk script.
So, answer the homework question.
Show us what you've tried to solve this on your own.
Hi I am having a code as stated below
module abcd( a , b , c ,da , fa, na , ta , ma , ra ,
ta, la , pa );
input a , b, da ,fa , na , ta , ma;
output c , ra ,ta ,
la ,pa ;
wire a , b , da , fa ,na ,
ta , ma;
endmodule
I need to match the string... (1 Reply)
I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with:
wc -l *|sort
15263 Image.txt
16401 reference.txt
40459 richtexteditor.txt
How can I also print the number of unique lines in each file?
15263 1401 Image.txt
16401... (15 Replies)
In the awk below I am trying to print out those lines in file2 that are no between $2 and $3 in file1. Both files are
tab-delimeted and I think it's close but currently it is printeing out the matches. The --- are not part of the files they are just to show what lines match or fall into
the range... (6 Replies)
Hi,
In an ideal scenario, I will have a listing of db transaction log that gets copied to a DR site and if I have them all, they will be numbered consecutively like below.
1_79811_01234567.arc
1_79812_01234567.arc
1_79813_01234567.arc
1_79814_01234567.arc
1_79815_01234567.arc... (3 Replies)
Hi Guru's,
I am trying to grep a range of line numbers (based on match) and then look for another match which starts with a special character '$' and print the line number. I have the below code but it is actually printing the line number counting starting from the first line of the range i am... (15 Replies)
Hi,
I have a file as below
This is the line one
This is the line two
<\XMLTAG>
This is the line three
This is the line four
<\XMLTAG>
Output of the SED command need to be as below.
This is the line one
This is the line two
<\XMLTAG>
Please do the need to needful to... (4 Replies)
Hello guys,
I am a beginner in Unix :wall: and was wondering if anyone could help me.
I need a script that prints lines that only has Z-value lower than equals to (<=) 1.0e-02. Each column is seperated by a tab.
10009.fd Z-value = 3.62843e-03
10009.fd Z-value = 9.75489e-01... (3 Replies)
Hi all,
on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern.
the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/'
I need to include the... (1 Reply)
Hi,
Anyone help me to print the lines from the flat file between 879th line number and 1424th line number.
The 879 and 1424 should be passed as input to the shell script(It should be dynamic).
Can any one give me using sed or awk?
I tried using read, and print the lines..Its taking too... (3 Replies)
hi
My problem now is that if shipping options as -o length = 88
it says the following:
# lp -o length=88 -dhp4015 /etc/hosts
UX:lp: ERROR: The following options can't be handled:
-o length=
TO FIX: The printer(s) that otherwise qualify
for printing your request can't handle
one or more of... (2 Replies)