Sponsored Content
Full Discussion: retrieve text after grep
Top Forums UNIX for Dummies Questions & Answers retrieve text after grep Post 302100122 by zazzybob on Saturday 16th of December 2006 07:20:18 PM
Old 12-16-2006
There's almost certainly a more efficient/elegant way of doing this, but the following works for me:

Code:
$ cat ./foo.awk
{
         if ( $0 ~ /<mainacc>/ ) {
            sub( /<mainacc>/, "", $0 )
            sub( /<\/mainacc>/, "", $0 )
            mainacc=$0
            printf( "mainacc: %s\n", $0 )
         }
         if ( $0 ~ /<AccId>/ ) {
            sub( /<AccId>/, "", $0 )
            sub( /<\/AccId>/, "", $0 )
            accid=$0
            printf( "\tAccId: %s", $0 )
         }
         if ( $0 ~ /<Value>/ ) {
            sub( /<Value>/, "", $0 )
            sub( /<\/Value>/, "", $0 )
            value=$0
            printf( "\tValue: %s\n", $0 )
         }
}
$ awk -f ./foo.awk infile
mainacc: 5500
        AccId: 1        Value: 0
        AccId: 2        Value: 0
mainacc: 5501
        AccId: 1        Value: 55555
        AccId: 2        Value: 6
mainacc: 5505
        AccId: 1        Value: 10
        AccId: 2        Value: 100

Cheers
ZB
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies

2. UNIX for Dummies Questions & Answers

retrieve lines using sed, grep or awk

Hi, I'm looking for a command to retrieve a block of lines using sed or grep, probably awk if that can do the job. In below example, By searching for words "Third line2" i'm expecting to retrieve the full block starting with 'BEGIN' and ending with 'END' of the search. Example: ... (3 Replies)
Discussion started by: learning_linux
3 Replies

3. Shell Programming and Scripting

grep command to retrieve one file

The Sed/Grep command is really confusing me. I know I'm missing something that should be really easy to fix. My program displays multiple names after I ask it to display only one, How do I get it to do only one?? it looks like this: Please enter a name to display? >> John (A list then... (9 Replies)
Discussion started by: toejam
9 Replies

4. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

5. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

6. Shell Programming and Scripting

How can i run sql queries from UNIX shell script and retrieve data into text docs of UNIX?

Please share the doc asap as very urgently required. (1 Reply)
Discussion started by: 24ajay
1 Replies

7. Shell Programming and Scripting

Perl code to retrieve text from website

perl -MLWP::Simple -le '$s=shift;$c=get("http://www.google.com/intl/en/chrome/devices/chromecast/$s/");$c=~/meta content=(.*?)name=\"Remote free\"/msg; print length($1),"\t$1"' ?gclid=CJDg27OdnL0CFcFlOgodFD8A6Q >output.txt output.txt should be: Chromecast works with devices you already own,... (9 Replies)
Discussion started by: cmccabe
9 Replies

8. Shell Programming and Scripting

Retrieve information Text/Word from HTML code using awk/sed

awk/sed newbie here. I have a HTML file and from that file and I would like to retrieve a text word. <font face=arial size=-1><li><a href=/value_for_clients/Tokyo/abc_process.txt>abc</a> NDK Version: 4.0 </li> <font face=arial size=-1><li><a... (6 Replies)
Discussion started by: sk2code
6 Replies

9. UNIX for Beginners Questions & Answers

How to search a text in file and retrieve required lines following it with UNIX command?

I have requirement to search for a text in the file and retrieve required lines that is user defined with unix command. Eg: Find the text UNIX in the below file and need to return Test 8 & Test 9 Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can... (8 Replies)
Discussion started by: Arunkumarsak4
8 Replies

10. UNIX for Beginners Questions & Answers

Grep: Retrieve two strings from one file to find them anyone on line in another file

I am having trouble matching *two* strings from one file anywhere in a line of a second file, and could use some help getting this figured out. My preference would be to use grep for this because I would like to take advantage of its -A option. The latter is due to the fact that I would like both... (2 Replies)
Discussion started by: jvoot
2 Replies
FOX(1)							      General Commands Manual							    FOX(1)

NAME
fox - ab-initio structure determination from diffraction data SYNOPSIS
fox [options] [file.xml] DESCRIPTION
The fox (Free Objects for Crystallography) program was made for the ab initio crystal structure solution from diffraction data. Its most interesting features for ab initio structure determination are: * versatile description of the crystal contents; * automatic correction for special positions and shared atoms between polyhedra; * the ability to use simultaneously multiple powder patterns; * smart global optimization algorithms; * a graphical interface with a 3D crystal structure view and live updates during the optimization process. OPTIONS
This program my be executed with or without command line options or input file (file.xml). It follows the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the fox wiki http://objcryst.sourceforge.net/Fox/Manual --help Show summary of options. --loadfouriergrd map.grd Load and display 'map.grd' fourier map with (first) crystal structure --loadfourierdsn6 map.DN6 Load and display a DSN6 fourier map with (first) crystal structure --nogui Run without GUI, automatically launches optimization --nogui may be accompanied by the following options: -n 10000 Run for 10000 trials at most (default: 1000000) --nbrun 5 Do 5 runs, randomizing before each run (default: 1), use -1 to run indefinitely -o out.xml Output in 'out.xml' --randomize Randomize initial configuration --silent Produce (almost) no text output --finalcost 0.15 Run optimization until cost < 0.15 --cif2pattern 1.5406 170 5000 .1 Simulate pattern for input crystal, wavelength=1.5406 up to 170o with 500 points anda peak width of 0.1o EXAMPLES
Fox silicon.xml Load file 'silicon.xml' and launch GUI. Fox Cimetidine-powder.xml --nogui --randomize -n 1000000 -o best.xml Load file 'ktartrate.xml', randomize, then make 1 optimization of 1 million trials, and save the best structure in 'best.xml'. Fox Cimetidine-powder.xml --nogui --randomize -n 10000000 --nbrun 10 -o best.xml Load file 'Cimetidine-powder.xml', then make 10 runs (starting from a random structure) of 10 million trials (each run saves one xml file), and save the best structure in 'best.xml'. Fox Cimetidine-powder.xml --nogui --silent --randomize -n 10000000 --nbrun 10 --finalcost 200000 -o best.xml Load file 'Cimetidine-powder.xml', then make 10 silent runs of 10 million trials (each run saves one xml file), and save the best structure in 'best.xml'. For each run, the optimization stops if the cost goes below 200000. AUTHOR
fox was written by Vincent Favre-Nicolin <Vincent.Favre-Nicolin@cea.fr>. This manual page was written by Carlo Segre <segre@debian.org>, for the Debian project (but may be used by others). July 24, 2008 FOX(1)
All times are GMT -4. The time now is 03:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy