Sponsored Content
Top Forums Shell Programming and Scripting Sed: Working on a line Previous to a pattern. Post 302431088 by mussen on Monday 21st of June 2010 02:48:05 AM
Old 06-21-2010
Yes! Great, Ok Now i had tried that before but with little success, but Getting me to print the original string again made me realize the error of my ways.

The Trick is to run that first before the rest of the statement! Another gotcha is that NJ Transit is using windows Line breaks, so i have to dump those before I can get a reliable string. So i have to run a tr -d "\r" first, then Join every 2 lines. Wooo I really should have seen that, but i suppose i am running a tad low on sleep. Give me a moment to post the final command.

---------- Post updated at 02:33 AM ---------- Previous update was at 02:23 AM ----------

Code:
curl -silent http://dv.njtransit.com/mobile/tid-mobile.aspx?sid=NY |grep '<tr width="100%"' | tr -d "\r" | sed 'N;s/\n/ /;s/&nbsp;//g;s/<\/td>/,/g;s/<[^>]*>//g;s/  \/ /,/g;s/ to //g;s/, /,/g;s/ ,/,/g;s/,$//'

OK, thats what I have for my final statement, I just had to tidy it up a bit at the end, but its working great! Thanks for the help!

---------- Post updated at 02:48 AM ---------- Previous update was at 02:33 AM ----------

And here.....Is a single line that will Print Status of all the trains into a CSV called test.csv (even with a header)
Code:
echo "Time","Train","Destination","Line","Track","Status">test.csv && curl -silent http://dv.njtransit.com/mobile/tid-mobile.aspx?sid=NY |grep '<tr width="100%"' | tr -d "\r" | sed 'N;s/\n/ /;s/&nbsp;//g;s/<\/td>/,/g;s/<[^>]*>//g;s/  \/ /,/g;s/ to //g;s/, /,/g;s/ ,/,/g;s/,$/"/;s/,/","/g;s/^/"/;s/"Track"/""/g' >>test.csv

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

return previous line for pattern match

Hi, Need some idea on file processing, I have file like below, Processing al sources ... ...No value found : CHECK. Completed comparing all sources. Comparing schedulers... Processing al targets ... ...No value found : From above I need to extract the line where "No value... (4 Replies)
Discussion started by: braindrain
4 Replies

2. Shell Programming and Scripting

Printing previous line based on pattern using sed

Hi, I have a written a shell script to get the previous line based on the pattern. For example if a file has below lines: ---------------------------------------------- #UNBLOCK_As _per #As per 205.162.42.92 #BLOCK_As_per #----------------------- #input checks abc.com... (5 Replies)
Discussion started by: Anjan1
5 Replies

3. Shell Programming and Scripting

Append next line to previous line when one pattern not found

Hi, I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are... (4 Replies)
Discussion started by: kannansr621
4 Replies

4. Shell Programming and Scripting

sed: how to move matched pattern to end of previous line

Hello, I'm new to this forum. I've been doing a lot of sed work lately and have found many useful tips on this forum. I've hit a roadblock in a project, though, and could really use some help. I have a text file with many lines like the following, i.e., some lines begin with a single word... (3 Replies)
Discussion started by: paroikoi
3 Replies

5. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

6. Shell Programming and Scripting

awk to insert line previous to a pattern?

I have a very long line with certain patters embedded in there. I need to be able to read that line, and when it encounters that pattern, create a new line. I want the pattern to be the beginning of the new line. I thought sed or awk could do this, but everything I try in sed gives me a "sed... (2 Replies)
Discussion started by: Drenhead
2 Replies

7. Shell Programming and Scripting

sed : match one pattern then the next consecutive second pattern not working

Ive used this snippet of code on a solaris box thousands of times. But it isnt working on the new linux box sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf its driving me nuts !! Is there something Im missing ? (7 Replies)
Discussion started by: popeye
7 Replies

8. Shell Programming and Scripting

Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone, im new here, and also programming with awk, sed and grep commands on linux. In my text i have many lines with this config: 1 1 4 3 1 1 2 5 2 2 1 1 1 3 1 2 1 3 1 1 1 2 2 2 5 2 4 1 3 2 1 1 4 1 2 1 1 1 3 2 1 1 5 4 1 3 1 1... (3 Replies)
Discussion started by: satir
3 Replies

9. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

10. Shell Programming and Scripting

How to delete the previous line after pattern match?

Team, I am writing a shell script to perform few health checks of the system, where I need to delete the previous line in the text file after pattern match using sed (or) awk. Could you please help me out on this? For example, <td> <td style=color:green align=center> </td> </tr>... (6 Replies)
Discussion started by: Nagaraj R
6 Replies
MOBILE-ATLAS-CREAT(1)					  mobile-atlas-creator User Manu				     MOBILE-ATLAS-CREAT(1)

NAME
mobile-atlas-creator - program to create atlas archive for mobile devices SYNOPSIS
mobile-atlas-creator DESCRIPTION
This manual page documents briefly the mobile-atlas-creator command. This manual page was written for the Debian distribution because the original program does not have a manual page. mobile-atlas-creator (formerly known as TrekBuddy Atlas Creator) is an open source (GPL) program which creates offline atlases for GPS handhelds and cell phone applications like TrekBuddy, AndNav and other Android and WindowsCE based applications. For the full list of supported applications please see the features section. Additionally individual maps can be exported as one large PNG image with calibration MAP file for OziExplorer. As source for an offline atlas Mobile Atlas Creator can use a large number of different online maps such as OpenStreetMap, Google Maps, Microsoft/Bing Maps, Yahoo Maps and many more online map providers. OPTIONS
The program does not have any options. AUTHOR
Ying-Chun Liu <paulliu@debian.org> Wrote this manpage for the Debian system. COPYRIGHT
Copyright (C) 2010 Ying-Chun Liu (PaulLiu) This manual page was written for the Debian system (and may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or (at your option) any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. mobile-atlas-creator 06/05/2012 MOBILE-ATLAS-CREAT(1)
All times are GMT -4. The time now is 10:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy