awk to print lines based on string match on another line and condition
Hi folks,
I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and then its version number tab or comma delimited. Id like to use awk as Im trying to get more familiar with it, with a search string that says something like /^ *Location:.*Adobe/ to help determine which entries are applicable, and then print 4 and 6 lines before that. I cant figure out how to do that, and then on top of it, the main catch is that some entries will satisfy the string match, but wont have the Version on the appropriate line (could be 3 instead of 4 lines before matched line), so there has to be a check like "if NR-3 or NR-4 starts with /^ ?Version/ print that and then whatever is 2 lines before that." Ive tried a ton of code snippets and approaches, but nothing even came close to working, so I havent included any.
Here is a bit of the source. Notice the 3rd entry would be an example of something that satisfies the string match but has Version and Software name 3 and 5 lines before instead of 4 and 6. I wouldnt want the 4th entry included at all. Thanks so much for any help!
The final output should look like this, so I can import it into excel:
Last edited by Franklin52; 06-11-2010 at 06:21 AM..
Reason: Please use code tags!
Dear friends, Please help me to resolve the problem below,
I have a file with following content:
date of file creation : 12 feb 2007
====================
= name : suresh
= city :mumbai
#this is a blank line
= date : 1st Nov 2005
====================
few lines of some text
this... (7 Replies)
I am parsing a nagios config, searching for a string, and then printing the line 2 lines later (the "members" string). Here's the data:
define hostgroup{
hostgroup_name chat-dev
alias chat-dev
members thisisahostname
}
define hostgroup{
... (1 Reply)
file1:
file2:
I need to find matches for any lines in file1 that appear in file2. Desired output is '>' plus the file1 term, followed by the line after the match in file2 (so the title is a little misleading):
This is honestly beyond what I can do without spending the whole night on it, so I'm... (2 Replies)
Data:
Pattern Data Data Data
Data Data Data
Data Data Data
...
With awk, how do I print the pattern matching line, then the subsequent lines following the pattern matching line. Varying number of lines following the pattern matching line. (9 Replies)
Hi All,
I have following listing
Filesystem GB blocks Free Used Iused Iused Mounted on
/dev/hd2 4.00 0.31 93 63080 43 /usr
Filesystem GB blocks Free Used Iused Iused Mounted on
Filesystem GB blocks Free Used Iused Iused... (11 Replies)
Hi,
I have a file like below.
1,2,3,4,5,6,7,8,9I would like to print or copied to a file based of line count in perl
If I gave a condition 1 to 3 then it should iterate over above file and print 1 to 3 and then again 1 to 3 etc.
output should be
1,2,3
4,5,6
7,8,9 (10 Replies)
I need to fetch particular string from log file based on grep condition match.
Actual requirement is need to print the next word from the same line based on grep string condtion match.
File :Java.lanag.xyz......File copied completed : abc.txt
Ouput :abc.txt
I have used below... (5 Replies)
URGENT HELP IS NEEDED!!
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
- Also the matching lines are not moving out of File1.txt
... (1 Reply)
Hi, I am trying to do something like this ...
I use awk to match a pattern, and then print out all col.
My code is :
awk '{if ($1 ==300) print $1,$2-'$sbin7',$3}' tmp.txt
output=
300 2
whereby sbin7=2,
The thing is, I want to print all col and row, not just the matched line/row only, but... (10 Replies)
Hi All,
I have problem in the middle of implementing to users, whereby the complaint is all about the decimal place which is too long. I need two decimal places only, but the outcome from command is always fixed to 6.
See the sample :
before:
Sort Total
Site Sort SortName Parts ... (3 Replies)
Discussion started by: horsepower
3 Replies
LEARN ABOUT DEBIAN
lgfile
LGFILE(5) BP configuration files LGFILE(5)NAME
lgfile - ION Load/Go source file
DESCRIPTION
The ION Load/Go system enables the execution of ION administrative programs at remote nodes:
The lgsend program reads a Load/Go source file from a local file system, encapsulates the text of that source file in a bundle, and
sends the bundle to a designated DTN endpoint on the remote node.
An lgagent task running on the remote node, which has opened that DTN endpoint for bundle reception, receives the extracted payload of
the bundle -- the text of the Load/Go source file -- and processes it.
Load/Go source file content is limited to newline-terminated lines of ASCII characters. More specifically, the text of any Load/Go source
file is a sequence of line sets of two types: file capsules and directives. Any Load/Go source file may contain any number of file
capsules and any number of directives, freely intermingled in any order, but the typical structure of a Load/Go source file is simply a
single file capsule followed by a single directive.
Each file capsule is structured as a single start-of-capsule line, followed by zero or more capsule text lines, followed by a single end-
of-capsule line. Each start-of-capsule line is of this form:
[file_name
Each capsule text line can be any line of ASCII text that does not begin with an opening ([) or closing (]) bracket character.
A text line that begins with a closing bracket character (]) is interpreted as an end-of-capsule line.
A directive is any line of text that is not one of the lines of a file capsule and that is of this form:
!directive_text
When lgagent identifies a file capsule, it copies all of the capsule's text lines to a new file named file_name that it creates in the
current working directory. When lgagent identifies a directive, it executes the directive by passing directive_text to the pseudoshell()
function (see platform(3)). lgagent processes the line sets of a Load/Go source file in the order in which they appear in the file, so the
directive_text of a directive may reference a file that was created as the result of processing a prior file capsule line set in the same
source file.
Note that lgfile directives are passed to pseudoshell(), which on a VxWorks platform will always spawn a new task; the first argument in
directive_text must be a symbol that VxWorks can resolve to a function, not a shell command. Also note that the arguments in
directive_text will be actual task arguments, not shell command-line arguments, so they should never be enclosed in double-quote characters
("). However, any argument that contains embedded whitespace must be enclosed in single-quote characters (') so that pseudoshell() can
parse it correctly.
EXAMPLES
Presenting the following lines of source file text to lgsend:
[cmd33.bprc
x protocol ltp
]
!bpadmin cmd33.bprc
should cause the receiving node to halt the operation of the LTP convergence-layer protocol.
SEE ALSO lgsend(1), lgagent(1), platform(3)perl v5.14.2 2012-05-25 LGFILE(5)