Don ed solution worked great.. I never used it, I need to understand how its working. syntax looks very close to sed. I wish I could use a single like sed for this.
Hi, sed was based on ed; ed came first. ed can do forwards and backwards searches; sed can't do backwards searches. The syntax for the ed g command is:
It tells ed to identify every line in the file that matches the basic regular expression BRE and for each line found, execute command on that line. And command in this case is:
where p is the print command which takes zero, one, or two addresses to specify a range of lines to be printed. (No addresses prints the current line; one address prints the addressed line, and two addresses (separated by a comma) prints the lines from the 1st address up to and including the 2nd address.) The address specified by ?BRE1? searches for the line matching the basic regular expression BRE1 backwards from the current line and (as with sed) /BRE2/ searches forwards from the current line for a line matching the basic regular expression BRE2.
With your new sample input, the ed script I suggested should still print the lines you want. And, if you like to write less portable, 1-liners instead of code that will work with any POSIX-conforming shell, you can translate this to:
The above works with both 1993 or later versions of ksh and bash, but is a syntax error for many other POSIX-compliant shells.
And, if you want to strip two <tab> characters from the front of each of those lines, you could use:
You could turn that into a 2-liner, but I much prefer readable and maintainable code to the minimal line approach.
This User Gave Thanks to Don Cragun For This Post:
Hi, guys. I have one question:
I need to search for a string in a file, and then extract another string from the file and assign it to a variable.
For example:
the contents of the file (group) is below:
...
ftp:x:23:
mail:x:34
...
testing:x:2001
sales:x:2002
development:x:2003
...... (6 Replies)
Hi,
There's an xml file produced from a front-end tool as shown below:
<INPUT DATABASE ="ORACLE" DBNAME ="UNIX" NAME ="FACT_TABLE" OWNERNAME ="DIPS">
<INPUTFIELD DATATYPE ="double" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="STORE_KEY" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="15" SCALE... (6 Replies)
Hi,
I wish to grep for the first instance of <listen-address> value between the first <server></server> tag in an xml file.
Sample xml:
.........
<timeout-seconds>1500</timeout-seconds>
</jta>
<server>
<name>Adminserver_DEV</name>
... (9 Replies)
i need to extract the string between two tags,
input file is
<PersonInfoShipTo AddressID="446311709" AddressLine1="" AddressLine2="" AddressLine3="" AddressLine4="" AddressLine5="" AddressLine6="" AlternateEmailID="" Beeper="" City="" Company="" Country="" DayFaxNo="" DayPhone="" Department=""... (5 Replies)
Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed
Bold letters are the stations . The whole file has multiple stations .
Below example i wanted to search... (4 Replies)
Hello All,
I have an input sample data like below (In actual I have many columns and few million rows).
Column1,Column2
4,2
1,5
Hello,4
1,4
Hello,2
3,5
Hello,8
4,5
Need the output (using awk and/or sed preferably) like below. Here I need all the lines between 2 matching... (1 Reply)
Hi everyone,
So i'm struggling with an xml (log file) where we get information about some devices, so the logfile is filled with multiple "blocks" like that.
Based on the <devId> i want to extract this part of the xml file. If possible I want it to have an script for this, cause we'll use... (5 Replies)