| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Hi,
Put the following code into a file (say, sed-cmds.file) then run it like as from
your command line:
sed -f sed-cmds.file yourfile > logfile
This is somewhat exhaustive as it tries to do some error checking
on the inputs and also conditions the input for processing.
######################## START OF FILE #####################
/\n/!{
h
# CONDITION THE LINE INTO PROPER FORMAT
y/\t/ / ;# CONVERT TABS TO SPACES
s/[ ][ ][ ]*/ /g ;# SQUEEZE MULTIPLE SPACES
s/^[ ]// ;# DELETE LEADING SPACE
s/[ ]$// ;# DELETE TRAILING SPACE
# CHECK FOR PRESENCE OF FIELD 8
# QUIT ON BAD INPUT
#^f1 f2 f3 f4 f5 f6 f7 f8...$
s/[ ]/&/7;tbadinp
# CHECK FOR PRESENCE OF FIELD 7
#^f1 f2 f3 f4 f5 f6 f7$
s/[ ]/&/6;tok
# WE"RE HERE => NUMBER OF FIELDS WERE < 7
# SO QUIT ON BAD INPUT
bbadinp
# PUT NEWLINES IN PLACE OF SPACES AFTER
# FIELDS 4, 5, 6, & 7.
:ok
s/\([^ ]*\)[ ]/\1\
/4;
:more
s/\(\(\n\).*\)[ ]/\1\2/
tmore
s/$/\
/;
# PRINT LEADING HTML MARKER PER LINE
x;s|.*|<TR>|p;x
}
# PLACE A NEWLINE AT THE END OF FIELDS 1, 2, & 3
# THEN GO PROCESS IT
/[ ]/{
s//\
/;
bprocess
}
# CONVERT NEWLINES TO SPACES FOR FIELDS 4, 5, & 6
/\n.*\n/{
s/\n/ /
s// /
}
# ENROBE THE FIELD WITH HTML MARKER <TD> ... </TD>
:process
s|^|<TD> |
s|\n| </TD>&|
P;/\n.*\n/D
# PRINT TRAILING HTML MARKER PER LINE
# THEN YOURE DONE FOR THIS LINE.
s|.*|</TR>|;b
# QUIT ON SEEING A BAD INPUT LINE
# GOOD LINE => NUMBER OF FIELDS == 7
:badinp
s/.*/[ERROR] BAD INPUT LINE/p
s/.*/SEEN ON LINE NUMBER:/p;=
s/.*/A GOOD INPUT LINE HAS EXACTLY 7 FIELDS./p
g;s/.*/>>> & <<</;q
##################### EOF ######################
-- Rakesh
---In [email protected], <rachid.mokrani@...> wrote :
Hi,
Using data from a text file I want to create an HTML table.
I have a first file with data like : (this file is generate automatically, and the line order can change )
google.com FR OK 2 September 2015 21
yahoo.com FR OK 3 September 2016 125
dell.com US OK October 3, 2017 365
oracle.com EN NO 3 December 2015 542
ibm.com ES OK November 18, 2015 21
sap.com ES NO January 26, 2018 36
mysql.com US OK 7 Jul 2016 25
etc ....
[Non-text portions of this message have been removed]