Sponsored Content
Top Forums Shell Programming and Scripting looking for expert sed/script help for translation/substitution Post 302452527 by Bashingaway on Friday 10th of September 2010 11:46:16 PM
Old 09-11-2010
This should be enough to get you started down the right track.....

Code:
XMLINPUTFILE=`cat /tmp/xmlinputfile.txt`
OIDTSIDSIDREF=`cat /tmp/oidtsidsid.txt`
STARTTIME=`echo $XMLINPUTFILE | sed -e '/programme start/!d' -e 's/<programme start="//' -e 's/ .*//g'`
STOPTIME=`echo $XMLINPUTFILE | sed -e '/programme start/!d' -e 's/.*stop="//' -e 's/ .*//g'`
CHANNELNO=`echo $XMLINPUTFILE | sed -e '/programme start/!d' -e 's/..*channel="//' -e 's/".*//'`
OIDCHANNEL=`echo "$OIDTSIDSIDREF" | grep $CHANNELNO `

OIDVAL=`echo "$OIDCHANNEL" | sed -e 's/:.*//' -e 's/abcdef/ABCDEF/g'`
TSIDVAL=`echo "$OIDCHANNEL" | sed -e 's/^[0-9]*://' -e 's/:.*//' -e 's/abcdef/ABCDEF/g'`
SIDVAL=`echo "$OIDCHANNEL" | sed -e 's/[0-9].*://' -e 's/=chan.*//' -e 'y/abcdef/ABCDEF/'`

OIDVAL=`echo "ibase=16; $OIDVAL" | bc`
TSIDVAL=`echo "ibase=16; $TSIDVAL" | bc`
SIDVAL=`echo "ibase=16; $SIDVAL" | bc`

OIDVAL=`printf "%04X" $(echo "$OIDVAL + 0" | bc -l ) | sed -e 'y/ABCDEF/abcdef/'`
TSIDVAL=`printf "%04X" $(echo "$TSIDVAL + 0" | bc -l ) | sed -e 'y/ABCDEF/abcdef/'`
SIDVAL=`printf "%04X" $(echo "$SIDVAL + 0" | bc -l ) | sed -e 'y/ABCDEF/abcdef/'`

STARTSTRING=`echo $STARTTIME | sed -e 's/...[0-9]/&-/' -e 's/.*-.[0-9]/&-/' -e 's/.*-.[0-9]/& /' -e 's/..* [0-9][0-9]/&:/' -e 's/..*:../&:/'`
STOPSTRING=`echo $STOPTIME | sed -e 's/...[0-9]/&-/' -e 's/.*-.[0-9]/&-/' -e 's/.*-.[0-9]/& /' -e 's/..* [0-9][0-9]/&:/' -e 's/..*:../&:/'`
STARTUNIX=`date -d "$STARTSTRING" +%s`
STOPUNIX=`date -d "$STOPSTRING" +%s`
DIFFERENCE=`expr $STOPUNIX - $STARTUNIX`

echo "<service oid="'"'"$OIDVAL"'"'" tsid="'"'"$TSIDVAL"'"'" sid="'"'"$SIDVAL"'"'">"
echo "<time start_time="'"'"$STARTUNIX"'"'" duration="'"'"$DIFFERENCE"'"'"/>"

Have fun

---------- Post updated at 04:46 AM ---------- Previous update was at 04:41 AM ----------

I just noticed a typo....

On the first instance of OIDVAL and TSIDVAL the end 's/abcdef/ABCDEF/g' should read 'y/abcdef/ABCDEF/' as in the first SIDVAL line.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitution using SED

Hi , I am stuck up in the below scenario:- I need to read a file name (eg A.txt) name frm another file (eg B.txt) and then I need to search for a particular expression in A.txt and substitute it with another expression. How can I use SED inside SHELL Scripting and command prompt as... (2 Replies)
Discussion started by: shubhranshu
2 Replies

2. Shell Programming and Scripting

SED Substitution

Hi , I am stuck up in the below scenario:- I need to read a file name (eg A.txt) name frm another file (eg B.txt) and then I need to search for a particular expression in A.txt and substitute it with another expression. How can I use SED inside SHELL Scripting and command prompt as well to... (1 Reply)
Discussion started by: shubhranshu
1 Replies

3. Shell Programming and Scripting

SED: language translation of a program

Hi people! I'm a bit noob at sed so I ask you for some help :( I'm trying to automatically translate some files of a program, which has some lines of this style: $string = 'A text line'; For example in this line: $string = 'The date entered: <strong>$a</strong> does not correspond... (2 Replies)
Discussion started by: pdmiguel
2 Replies

4. Shell Programming and Scripting

sed substitution

Hi I am trying to do a text insertion in a text file at a particular line number in a shell script. However its not working. sed '122i\ > for j in \`echo $MyList\` ; do perl -pi -e\'s#01\/01\/2009#01\/01\/2011#\' $j ; done' $HOME/MyScript.ksh The Actual line to be inserted at line 122... (5 Replies)
Discussion started by: som.nitk
5 Replies

5. Shell Programming and Scripting

sed substitution

Using sed I'm trying to replace 'string' with ']' while retaining case and ignoring words with 'string' in it along with additional characters like 'strings' and those which already contain the ] wrapper. I'm hoping to do it with sed and the right expression, if possible. Example: Apple... (2 Replies)
Discussion started by: tom.lee
2 Replies

6. UNIX for Dummies Questions & Answers

Help with sed substitution

I'm a noob to unix, and I have a line of data like the following: title=Boston|tcolor=green|desc=Large city in New England|url=www.boston.com Is there a way to change a field value with sed substitution? (i.e. change tcolor=green to tcolor=blue) I figured out: sed... (19 Replies)
Discussion started by: stabby
19 Replies

7. Shell Programming and Scripting

Substitution with sed

I have a file with some numbers having single quotes around them which I want to remove. i.e. '923930' -> 23930 If it can be done without using sed thats fine. I have tried with sed but can't think how to replace this pattern on only the numbers (13 Replies)
Discussion started by: user_invalid
13 Replies

8. UNIX for Dummies Questions & Answers

sed substitution

How can you use sed with a line of code that reads: 67899:Bill:Williams:Maple Dr.:45908600 Let us say we want to replace Maple Dr. with Oak St. (1 Reply)
Discussion started by: yonkers062986
1 Replies

9. Shell Programming and Scripting

sed variable substitution in a script

Hi I am trying to do the following in a script find a string and add in a block of text two lines above on the command line this works fine #/usr/bin/cat /usr/local/etc/dhcpd.conf_subnet | /usr/xpg4/bin/sed -n -e '1h;1\!H;${;g;s/}.*#END of 10.42.33.0/#START of RANGE $dstart\:option... (3 Replies)
Discussion started by: eeisken
3 Replies

10. Shell Programming and Scripting

regarding TCL expert SSH script

Hi, I am in learning curve in the Tcl/expert language. I have the following program for ssh #!/dsbutest/autotest/ats_current/bin/expect set UserID "user" set Password "key" set remotehost spawn ssh -l $UserID $remotehost expect -re ".*" send "yes\r" #this one adding the RSA key... (1 Reply)
Discussion started by: mathiaga
1 Replies
UNBUFFER(1)						      General Commands Manual						       UNBUFFER(1)

NAME
unbuffer - unbuffer output SYNOPSIS
unbuffer program [ args ] INTRODUCTION
unbuffer disables the output buffering that occurs when program output is redirected from non-interactive programs. For example, suppose you are watching the output from a fifo by running it through od and then more. od -c /tmp/fifo | more You will not see anything until a full page of output has been produced. You can disable this automatic buffering as follows: unbuffer od -c /tmp/fifo | more Normally, unbuffer does not read from stdin. This simplifies use of unbuffer in some situations. To use unbuffer in a pipeline, use the -p flag. Example: process1 | unbuffer -p process2 | process3 CAVEATS
unbuffer -p may appear to work incorrectly if a process feeding input to unbuffer exits. Consider: process1 | unbuffer -p process2 | process3 If process1 exits, process2 may not yet have finished. It is impossible for unbuffer to know long to wait for process2 and process2 may not ever finish, for example, if it is a filter. For expediency, unbuffer simply exits when it encounters an EOF from either its input or process2. In order to have a version of unbuffer that worked in all situations, an oracle would be necessary. If you want an application-specific solution, workarounds or hand-coded Expect may be more suitable. For example, the following example shows how to allow grep to finish pro- cessing when the cat before it finishes first. Using cat to feed grep would never require unbuffer in real life. It is merely a place- holder for some imaginary process that may or may not finish. Similarly, the final cat at the end of the pipeline is also a placeholder for another process. $ cat /tmp/abcdef.log | grep abc | cat abcdef xxxabc defxxx $ cat /tmp/abcdef.log | unbuffer grep abc | cat $ (cat /tmp/abcdef.log ; sleep 1) | unbuffer grep abc | cat abcdef xxxabc defxxx $ BUGS
The man page is longer than the program. SEE ALSO
"Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" by Don Libes, O'Reilly and Associates, January 1995. AUTHOR
Don Libes, National Institute of Standards and Technology 1 June 1994 UNBUFFER(1)
All times are GMT -4. The time now is 01:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy