Parsing file: struggling against sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing file: struggling against sed command
# 8  
Old 11-22-2011
I updated the code... did you try that?... please check...
Code:
sed -n 's/.*HORA COMIENZO: \(.*\)/\1/p'

--ahamed
# 9  
Old 11-22-2011
Quote:
Originally Posted by ahamed101
I updated the code... did you try that?... please check...
Code:
sed -n 's/.*HORA COMIENZO: \(.*\)/\1/p'

--ahamed
Sorry, did not notice that

I am afraid this got worse:

Quote:
S_CAP0010001;2500;4008850 FILAS FICHERO SALIDA (contando cabecera y pie): 4007593 FILAS FICHERO NO MATCHS: 1255 HORA FIN: 2011-11-18 12:27:33 STATUS: 2( Finalizado OK con warnings );;
S_CAP0010002;2500;1629608 FILAS FICHERO SALIDA (contando cabecera y pie): 1629326 FILAS FICHERO NO MATCHS: 280 HORA FIN: 2011-11-18 14:01:57 STATUS: 2( Finalizado OK con warnings );;
S_CAP0010008;2500;8654037 FILAS FICHERO SALIDA (contando cabecera y pie): 76984 FILAS FICHERO NO MATCHS: 8577051 HORA FIN: 2011-11-18 14:29:15 STATUS: 2( Finalizado OK con warnings );;
S_GIE0010008;157;;;
# 10  
Old 11-22-2011
You want the solution in sed itself? We can do it... I think the issue is cause everything is treated as one line

Try this in the mean time...
Code:
ultfichlog=`ls -rt $rutalogs/$proceso* | tail -1`
awk '/JOB/{f1=$NF} {f2=2500}
/FILAS ENTRADA/{f3=$NF} /HORA COMIENZO/{f4=$(NF-1) $NF}
/HORA FIN/{f5=$(NF-1) $NF; print f1";"f2";"f3";"f4";"f5}' $ultfichlog

And I have no idea where 2500 is coming from, so for now I hard coded it!

---------- Post updated at 06:17 AM ---------- Previous update was at 06:13 AM ----------

SED modified
Code:
numfilas_IN=`echo $fichlog | sed -n 's/.*FILAS ENTRADA (contando carcasa, cabecera y pie): \([^ ]*\).*/\1/p' `
horacomienzo=`echo $fichlog | sed -n 's/.*HORA COMIENZO: \([^A-Z]*\).*/\1/p' `
horafin=`echo $fichlog | sed -n 's/.*HORA FIN: \([^A-Z]*\).*/\1/p' `
echo "$proceso;$longfila;$numfilas_IN;$horacomienzo;$horafin"

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 11  
Old 12-21-2011
Quote:
Originally Posted by ahamed101
You want the solution in sed itself? We can do it... I think the issue is cause everything is treated as one line

Try this in the mean time...
Code:
ultfichlog=`ls -rt $rutalogs/$proceso* | tail -1`
awk '/JOB/{f1=$NF} {f2=2500}
/FILAS ENTRADA/{f3=$NF} /HORA COMIENZO/{f4=$(NF-1) $NF}
/HORA FIN/{f5=$(NF-1) $NF; print f1";"f2";"f3";"f4";"f5}' $ultfichlog

And I have no idea where 2500 is coming from, so for now I hard coded it!

---------- Post updated at 06:17 AM ---------- Previous update was at 06:13 AM ----------

SED modified
Code:
numfilas_IN=`echo $fichlog | sed -n 's/.*FILAS ENTRADA (contando carcasa, cabecera y pie): \([^ ]*\).*/\1/p' `
horacomienzo=`echo $fichlog | sed -n 's/.*HORA COMIENZO: \([^A-Z]*\).*/\1/p' `
horafin=`echo $fichlog | sed -n 's/.*HORA FIN: \([^A-Z]*\).*/\1/p' `
echo "$proceso;$longfila;$numfilas_IN;$horacomienzo;$horafin"

--ahamed

Hey guy,

sorry for being so long time to answer, I was thrown into something more urgent, and had to postpone this

Now I am getting back to this. I used your new sed commands, and this worked just great!!!

Quote:
S_CAP0010001;2500;4032144;2011-12-19 08:51:26 ;2011-12-19 08:57:44
S_CAP0010002;2500;1679905;2011-12-19 09:10:00 ;2011-12-19 09:14:23
S_CAP0010008;2500;8723635;2011-12-19 11:22:42 ;2011-12-19 11:37:25
ls: /opt/pagina2/datos/logs/S_GIE0010008*: No existe el fichero o el directorio
Still have some questions, hope you can help me

1. Is there any way I can remove final blank space in fourth column? (after date-time)

I tried the following but did not work:
Code:
horacomienzo=`echo $fichlog | sed -n 's/.*HORA COMIENZO: \([^A-Z]*\).*/\1/p' | sed 's/^ *//g' `

2. I would like final message not be displayed when I cant find any file matching my pattern. I added this to my code, but still getting message:

Code:
hayfichlog=`ls -rt $rutalogs/$proceso* | wc -l`
  if [ "${hayfichlog}" -ne "0" ]
  then
 ultfichlog=`ls -rt $rutalogs/$proceso* | tail -1`
....

---------- Post updated at 10:40 AM ---------- Previous update was at 10:23 AM ----------

Quote:
Originally Posted by manolain
Hey guy,

sorry for being so long time to answer, I was thrown into something more urgent, and had to postpone this

Now I am getting back to this. I used your new sed commands, and this worked just great!!!



Still have some questions, hope you can help me

1. Is there any way I can remove final blank space in fourth column? (after date-time)

I tried the following but did not work:
Code:
horacomienzo=`echo $fichlog | sed -n 's/.*HORA COMIENZO: \([^A-Z]*\).*/\1/p' | sed 's/^ *//g' `

2. I would like final message not be displayed when I cant find any file matching my pattern. I added this to my code, but still getting message:

Code:
hayfichlog=`ls -rt $rutalogs/$proceso* | wc -l`
  if [ "${hayfichlog}" -ne "0" ]
  then
 ultfichlog=`ls -rt $rutalogs/$proceso* | tail -1`
....


I just got first problem sovled with this:

Code:
horacomienzo=`echo $fichlog | sed -n 's/.*HORA COMIENZO: \([^A-Z]*\).*/\1/p' | sed 's/^ *//;s/ *$//' `

Now trying the second
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble with sed and ini file parsing

hi people, i'm having a hard time trying to extract a list of vars delimited by section inside a ini file ... let's consider this ini file : ; config file DESC = "channel synchro TGG01" DMM_VER = DMM23 PATH_FIFO = /users/tgg00/fifo QRT = BTS01.TGG.01.2 MODE_TRACE... (5 Replies)
Discussion started by: odium74
5 Replies

2. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

3. UNIX for Advanced & Expert Users

Parsing through a file with awk/sed

I don't necessary have a problem, as I have a solution. It is just that there may be a better solution. GOAL: Part one: Parse data from a file using the "\" as a delimiter and extracting only the last delimiter. Part two: Parse same file and extract everything but the last delimited item. ... (8 Replies)
Discussion started by: OrangeYaGlad
8 Replies

4. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

5. Shell Programming and Scripting

Struggling with arrays and delimited file

Hi, I am trying to use arrays in my script but can not seem to get it to work. I have a file called sections, this contains headers from a tripwire log file, separated by "@" but could be "," if easier The headers will be used to cut sections from the log file into another to be mailed. ... (5 Replies)
Discussion started by: pobman
5 Replies

6. Shell Programming and Scripting

awk/sed for parsing file

Hi All, I have a log file like this E Mon Oct 06 00:17:08 2008 xxx2 cm:10614 fm_pi2_svc_iptv_purchase.c:149 1:pin_deferred_act:10601:11:169:1223245028:16 pi2_op_svc_iptv_purchase error <location=PIN_ERRLOC_FM:5 class=PIN_ERRCLASS_SYSTEM_DETERMINATE:1... (10 Replies)
Discussion started by: subin_bala
10 Replies

7. Shell Programming and Scripting

Parsing a file (sed/awk?)

Hello people, newbie question. I'm trying to parse these type of file 1 "CAR " " C1 " " " 6 0 C1 2 "CAR " " O1A" " " 8 0 O1A 3 "CAR " " O1B" " " 8 -1 O1B 4 "CAR " " C2 " " " 6 0 C2 5 "CAR " " C3 " " " 6 ... (10 Replies)
Discussion started by: aristegui
10 Replies

8. UNIX for Advanced & Expert Users

Parsing xml file using Sed

Hi All, I have this(.xml) file as: <!-- define your instance here --> <instance name='ins_C2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' > <property> </property> </instance> I want output as: <!-- define your instance here --> <instance... (3 Replies)
Discussion started by: kapilkinha
3 Replies

9. UNIX for Advanced & Expert Users

Help- Unix File Compare- Struggling

I had posted this earlier about 3 weeks ago and had recieved a response and I did sort both the files and the comm command is still not working. Can someone please assist me, I would really appreciate it. Below is what I am trying to do I need to compare File A with File B and create FILE C... (2 Replies)
Discussion started by: guiguy
2 Replies

10. Shell Programming and Scripting

Struggling with a text file

Hi, I am struggling with the following... I try to grep out information of a text file I got with lynx, a text browser. The text file I get from lynx with dump is attached in the bottom. What I would like to get is another file containing the astro-ph/98324 (number) and title and list of... (13 Replies)
Discussion started by: pau
13 Replies
Login or Register to Ask a Question