Results 1 to 8 of 8
Hi all, I have been working creating part of a script for the past fours days and am so close to getting it finished but I'm stuck on one thing.
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 10-30-2012 #1Just Joined!
- Join Date
- Aug 2004
- Location
- Melbourne, Australia
- Posts
- 14
formatting two lines of output into one line
Hi all, I have been working creating part of a script for the past fours days and am so close to getting it finished but I'm stuck on one thing.
I have a folder containing a large number of files and I need the values for two strings within each file.
To begin with I am searching one file and when I have my code right will put it in a for loop to search every file.
My code so far is:
Which pulls out the two strings, does a bit of tidying up and produces the following:Code:grep -E "string1|string2" file | sed 's/div\ class\=\"string1\"/\br\ \//g' | sed 's/div\ class\=\"string2\"/\hr\ \//g' | sed s'/<\/div>//g'
<br />outputline1
<hr />outputline2
I just need these two lines to on one line, so:
<br />outputline1<hr />outputline2
I hope someone may be able to help? I've searched a fair bit and seen lots of references to <tr> but none have worked when applied in my case. I look at this and it seems line it should be such a simple fix, I just can't figure it out!
- 10-30-2012 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 468
something like this seems to work OK
tr -d "\n" <a
where 'a' is the name of the file containing your two linesthe sun is new every day (heraclitus)
- 10-31-2012 #3Just Joined!
- Join Date
- Aug 2004
- Location
- Melbourne, Australia
- Posts
- 14
Thanks tpl - do I pipe into that last command though? I tried doing the following
and it just pulls in extra text from the file I'm reading, seemingly at random though I'm sure it isn't.Code:grep -E "string1|string2" file | sed 's/div\ class\=\"string1\"/\br\ \//g' | sed 's/div\ class\=\"string2\"/\hr\ \//g' | sed s'/<\/div>//g' | tr -d "\n" <file
Last edited by davidov31; 10-31-2012 at 08:42 AM.
- 11-01-2012 #4Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
hi,
all those pipes are probably useless.
one sed should be able to do the whole job.
can you paste a representative sample of input text file?
the same sed command can put all on one line.Code:sed -n '/string[12]/{s/div class="string1" \br //gs/div\ class\=\"string2\"/\hr\ \//g; s/<\/div>//g';s/div\ class\=\"string2\"/\hr\ \//g; s/<\/div>//g}' yourFile
give us input sample.
- 11-02-2012 #5Just Joined!
- Join Date
- Aug 2004
- Location
- Melbourne, Australia
- Posts
- 14
Thanks very much for that, it's really appreciated!
I hope I'm not assuming too much here but the text I'm looking for is contained in just a couple of specific lines in each file so I'm thihking there is not much point in pasting in a copy of what is quite a large file? I'm happy to do this if required however
Here is an example of the two lines I'm looking at
<div class="StockCodeCreators">(W) Duane Swierczynski & Various (A) Michael Avon Oeming & Various (CA) Michael Avon Oeming</div>
<div class="PreviewsHtml">Michael Avon Oeming's twisted antiheroes head to the pages of DHP, as a three-issue arc of The Victories begins! Also in this issue, get shanghaied by the premiere of Geoffrey Thorne and Todd Harris's Journeymen! Plus, the exciting conclusions of Resident Alien, Captain Midnight, Gamma, and White Suits, and all-new X!Last edited by davidov31; 11-02-2012 at 05:41 AM.
- 11-02-2012 #6Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
sorry, I can't find a way using sed (I'm not so keen on sed
)
using awk:are lines really one after the other.Code:awk '/<div class="StockCodeCreators|PreviewsHtml">/{gsub("<[^>]*>",""); printf("%s",$0)}'
you should have given us more than just the lines your looking for.
- 11-02-2012 #7Just Joined!
- Join Date
- Aug 2004
- Location
- Melbourne, Australia
- Posts
- 14
I thought it would be helpful to just post a snippet, here is the full file
- 11-02-2012 #8Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
no! no full file yet


Reply With Quote
