Sponsored Content
Top Forums Shell Programming and Scripting Extract lines from file using keywords using script Post 302770257 by RudiC on Friday 15th of February 2013 04:27:10 AM
Old 02-15-2013
What about opening a new thread, telling us what to do instead of leaving us guessing what goes where based on which criterion?

---------- Post updated at 10:27 ---------- Previous update was at 09:29 ----------

Well, trying and interpreting and guessing, I've come up with
Code:
awk     'BEGIN {print "IP\tHOST\tCARD\tSTATUS\tMAX\tTOT"}
         function prep (Ar)     {tmp=$0
                                 while ($0 != "") {getline; tmp=tmp $0}
                                 gsub (/[A-Za-z ()0-9]*: *|, *$/,"",tmp)
                                 return split (tmp, Ar, ",")}
         /^IP/ {IP = $NF}
         /^.local/ {gsub(/.local.|#context/, "", $1); HOST=$1}
         /^Card Status/ {n = prep (STAT) }
         /^Max Circuit/ {n = prep (MAX)  }
         /^Num.*TOTAL/  {n = prep (NUM);
                         for (i=1; i<=n; i++) print IP, HOST, i, STAT[i], MAX[i], NUM[i]}
        ' OFS="\t" file
IP    HOST    CARD    STATUS    MAX    TOT
10.238.52.65    pun-ras-bng-mhs-01    1    0    0    4
10.238.52.65    pun-ras-bng-mhs-01    2    1    32768    8959
10.238.52.65    pun-ras-bng-mhs-01    3    1    32768    10591
.
.
.
10.238.52.65    pun-ras-bng-mhs-01    14   1    4096    1
10.238.56.225   ngp-ras-bng-cto-01    1    1    32768    4916
10.238.56.225   ngp-ras-bng-cto-01    2    1    32768    10976
.
.
.

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture lines based on keywords

Hello everyone, I am trying to write a script that will capture few lines from a text file based on 2 keywords in the first line and 1 keyword in the last one. It could also be based on the first line only + the folllowing 3 lines. Could some one help or give directions. Thanks. (4 Replies)
Discussion started by: nimo
4 Replies

2. Shell Programming and Scripting

Script that extract some lines from a file lookin into another

I want a ksh script that parse two files (text files, actually my original files are .xls) - input data: - one file file1 containig lines separated by spaces (or other delimiter) - 2nd one file2 contain only one numerical value in a line (for simplicity but it might of the same form as the 1st)... (7 Replies)
Discussion started by: heartwork
7 Replies

3. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

4. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

5. UNIX for Dummies Questions & Answers

Reading specific lines from a file using index or keywords

Hello I want to read from a file which contains email addresses. The file format is like this. from@mail.com to1@mail.com to2@mail.com cc@mail.com bcc@mail.com I'll have to read from such file and assign the email addresses to respective variables. frommail =... (11 Replies)
Discussion started by: Kyaw Lwin Phyo
11 Replies

6. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

7. Shell Programming and Scripting

Script needed to extract few lines from file

Hello, I need a utility script or command that will extract the following lines from a file based on a 'word' contain in a line. For example my file contains lot of lines. So if i pass 1800182 to the script/command it should return everything between 1st RequestNetRates tag before it and 1st... (4 Replies)
Discussion started by: jakSun8
4 Replies

8. Shell Programming and Scripting

Extract word between two KEYWORDS

Hi I want to extract all the words between two keywords HELLO & BYE. eg: Input 1_HELLO_HOW_ARE_YOU_BYE_TEST 1_HELLO_WHERE_ARE_BYE_TEST 1_HELLO_HOW_BYE_TEST Output Required: HOW_ARE_YOU WHERE_ARE HOW (7 Replies)
Discussion started by: dashing201
7 Replies

9. Shell Programming and Scripting

Display lines between keywords inclusive

Hi, I have a file that contains a lot of lines that are repetitive. I am interested in grepping the following section which is repetitive. ::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::: <Address> <Street>xxxy</Street> ... (3 Replies)
Discussion started by: jakSun8
3 Replies

10. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies
PDF2TXT(1)							  PDFMiner Manual							PDF2TXT(1)

NAME
pdf2txt - extracts text contents of PDF files SYNOPSIS
pdf2txt [option...] file... DESCRIPTION
pdf2txt extracts text contents from a PDF file. It extracts all the text that is to be rendered programmatically, i.e. text represented as ASCII or Unicode strings. It cannot recognize text drawn as images that would require optical character recognition. It also extracts the corresponding locations, font names, font sizes, writing direction (horizontal or vertical) for each text portion. You need to provide a password for protected PDF documents when its access is restricted. You cannot extract any text from a PDF document which does not have extraction permission. OPTIONS
-o file Specifies the output file name. The default is to print the extracted contents to standand output in text format. -p pageno[,pageno,...] Specifies the comma-separated list of the page numbers to be extracted. Page numbers start at one. By default, it extracts text from all the pages. -c codec Specifies the output codec. -t type Specifies the output format. The following formats are currently supported: text Text format. This is the default. html HTML format. It is not recommended. xml XML format. It provides the most information. tag "Tagged PDF" format. A tagged PDF has its own contents annotated with HTML-like tags. pdf2txt tries to extract its content streams rather than inferring its text locations. Tags used here are defined in the PDF Reference, Sixth Edition[1] (S10.7 "Tagged PDF"). -D writing-mode Specifies the writing mode of text outputs: lr-tb Left-to-right, top-to-bottom. tb-rl Top-to-bottom, right-to-left. auto Determine writing mode automatically -M char-margin, -L line-margin, -W word-margin These are the parameters used for layout analysis. In an actual PDF file, text portions might be split into several chunks in the middle of its running, depending on the authoring software. Therefore, text extraction needs to splice text chunks. In the figure below, two text chunks whose distance is closer than the char-margin is considered continuous and get grouped into one. Also, two lines whose distance is closer than the line-margin is grouped as a text box, which is a rectangular area that contains a "cluster" of text portions. Furthermore, it may be required to insert blank characters (spaces) as necessary if the distance between two words is greater than the word-margin, as a blank between words might not be represented as a space, but indicated by the positioning of each word. Each value is specified not as an actual length, but as a proportion of the length to the size of each character in question. The default values are char-margin = 1.0, line-margin = 0.3, and W = 0.2, respectively. -n Suppress layout analysis. -A Force layout analysis for all the text strings, including text contained in figures. -V Enable detection of vertical writing. -s scale Specifies the output scale. This option can be used in HTML format only. -m n Specifies the maximum number of pages to extract. By default, all the pages in a document are extracted. -P password Provides the user password to access PDF contents. -d Increase the debug level. EXAMPLES
Extract text as an HTML file whose filename is output.html: $ pdf2txt -o output.html samples/naacl06-shinyama.pdf Extract a Japanese HTML file in vertical writing: $ pdf2txt -c euc-jp -D tb-rl -o output.html samples/jo.pdf Extract text from an encrypted PDF file: $ pdf2txt -P mypassword -o output.txt secret.pdf SEE ALSO
dumppdf(1) AUTHORS
Jakub Wilk <jwilk@debian.org> Wrote this manual page for the Debian system. Yusuke Shinyama <yusuke@cs.nyu.edu> Author of PDFMiner and its original HTML documentation. NOTES
1. PDF Reference, Sixth Edition http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference_1-7.pdf pdf2txt 08/24/2011 PDF2TXT(1)
All times are GMT -4. The time now is 07:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy