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!
Code:
Bridge CS3:
Version: 2.1.1.9
Last Modified: 11/6/08 10:27 AM
Kind: Universal
Get Info String: 2.1.1.9 (124992), Copyright 2003-2007, Adobe Systems, Inc.
Location: /Applications/Adobe Bridge CS3/Bridge CS3.app
Adobe Bridge CS4:
Version: 3.0.0.464
Last Modified: 9/15/09 5:34 PM
Kind: Universal
Get Info String: 3.0.0.464 (144651), Copyright 2003-2007, Adobe Systems, Inc.
Location: /Applications/Adobe Bridge CS4/Adobe Bridge CS4.app
Device Central:
Version: 1.1.0
Last Modified: 11/6/08 10:53 AM
Kind: Universal
Location: /Applications/Adobe Device Central CS3/Device Central.app
Chess:
Version: 2.4.1
Last Modified: 9/16/09 10:30 AM
Kind: Universal
Get Info String: 2.4.1, Copyright 2003-2008 Apple Inc.
Location: /Applications/Chess.app
The final output should look like this, so I can import it into excel:
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 CENTOS
t1asm
T1ASM(1) General Commands Manual T1ASM(1)NAME
t1asm - assemble PostScript Type 1 font
SYNOPSIS
t1asm [-a|-b] [-l length] [input [output]]
DESCRIPTION
t1asm assembles Adobe Type 1 font programs into either PFA (hexadecimal) or PFB (binary) formats from a human-readable form. If the file
output is not specified output goes to the standard output. If the file input is not specified input comes from the standard input.
t1asm tokenizes the charstring data and performs eexec and charstring encryption as specified in the ``black book,'' Adobe Type 1 Font For-
mat.
The input must have a line of the form
/-|{string currentfile exch readstring pop}executeonly def
which defines the command, in this case `-|', that is to start charstring data. It is an error not to define such a command. Another common
name for this command is `RD'.
After the start of the Subrs array in the input, all open braces `{' not in a comment begin a charstring. Such a charstring is terminated
by the next non-comment close brace `}'. Within such a charstring, only comments, integers, and valid charstring commands are allowed.
Valid charstring command names can be found in Adobe Type 1 Font Format and other documents describing the newer Type 2 opcodes. The format
within a charstring is unimportant as long as integers and commands are separated by at least a one whitespace (space, tab, newline) char-
acter. Note that within charstrings, comments are discarded because they cannot be encoded.
OPTIONS --pfa, -a
Output in PFA (ASCII) format.
--pfb, -b
Output in PFB (binary) format. This is the default.
--block-length=num, -l num
PFB only: Set the maximum output block length to num. The default length is as large as memory allows.
--line-length=num, -l num
PFA only: Set the maximum length of encrypted lines in the output to num. (These are the lines consisting wholly of hexadecimal dig-
its.) The default is 64.
EXAMPLES
% t1asm Utopia-Regular.raw > Utopia-Regular.pfb
% t1asm -a Utopia-Regular.raw > Utopia-Regular.pfa
SEE ALSO t1disasm(1), t1ascii(1), t1binary(1), t1unmac(1), t1mac(1)
Adobe Type 1 Font Format is available free from Adobe as a PDF file. http://partners.adobe.com/asn/developer/PDFS/TN/T1_SPEC.PDF
The Type 2 Charstring Format, also available from Adobe as a PDF file, describes the newer Type 2 operators, which are also used in some
multiple-master Type 1 fonts like Adobe Jenson and Kepler. http://partners.adobe.com/asn/developer/PDFS/TN/5177.Type2.pdf
AUTHORS
Lee Hetherington (ilh@lcs.mit.edu)
Eddie Kohler (ekohler@gmail.com)
Version 1.37T1ASM(1)