02-17-2009
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['identifier'] = 'A text line';
For example in this line:
$string['date'] = 'The date entered: <strong>$a</strong> does not correspond to the format shown in the example.';
I want to replace the string 'date' from the line but it should not affect to the string index. For example, replacing date with DATE should result only in:
$string['date'] = 'The DATE entered: <strong>$a</strong> does not correspond to the format shown in the example.';
(notice that $string['date'] must not replaced)
I've been trying a bit with sed, and I almost got something...
sed -e "s/$string\['\([a-z_0-9]*\)'\] = '\([^']*\)'/$string\['\1\'] = '\2'/g"
but I dont know how to replace the content readed in \2
.
Any1 can help me?
Thank you very much!
8 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Can someone tell me exactly what this code is doing?
#
# gnutest
#
# Test launch of ghostscript (gs) from a script
#
rm gnutest.ps
#
# ------- calculation that would generate file(s) to
# be plotted with gnuplot would be placed here -----------
#
gnuplot << \E-o-f2
set... (1 Reply)
Discussion started by: wmosley2
1 Replies
2. Shell Programming and Scripting
Hi,
I tried this with my shell program and it didn't work:
/usr/ucb/sed '/$employeeID/d' /usr1/log/logfile
How to let sed see my variable employeeID within my shell program?
Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies
3. Shell Programming and Scripting
This is my test script version:
#!/bin/sh
wget -q -O /tmp/axn 'http://www.axn.pt/programacion/'
sed -e '/^$/ d' /tmp/axn > /tmp/temp #Clean black space
sed -e 's/<*>//g' /tmp/temp > /tmp/temp1 #Remove HTML
rm -f /tmp/temp # Step by step script then clean one by one
sed... (3 Replies)
Discussion started by: single
3 Replies
4. UNIX for Advanced & Expert Users
i need a sample unix awk/sed program to replace param3 in a file.
i have sample file a.dat with the following format/length (week 8, sku 20, store 20 and qty 8). all store id's which end with _2 needs to be replaced with div id 2. all store id's which end with _1 needs to be replaced with div id... (4 Replies)
Discussion started by: mnnarendra
4 Replies
5. Shell Programming and Scripting
The following awk script creates a file b.dat.
awk '{print substr($0,1,27),substr($2,index($2,"_")+1)," ",substr($0,49)}' a.dat > b.dat
I need this script to be modified to also sum $3 values by distinct $1 and $2
fields.
Current file
W2_2009275 2 8
W2_2009275 2 7
W1_2009275 1... (3 Replies)
Discussion started by: mnnarendra
3 Replies
6. Shell Programming and Scripting
I want to substitute a charactor "PAN" with "TAN" in a shell, I used sed command in shell, it wo'nt work but the same is run from command prompt it was successful. the command is
sed ' s/PAN/TAN/g ' <i/p> > <o/p>
sed ' s/^M/^M/g ' <i/p> > <o/p> (1st ^M is Ctrl+V+M, 2nd should be line feed/next... (1 Reply)
Discussion started by: anil_kut
1 Replies
7. Shell Programming and Scripting
Hi All,
I'm looking for some expert help on sed/script to work out the best way to transform one xml format into another however there are a few complexities around translation.
The extra complexities are to:
1) take the start and stop time (YYYYMMDDHHMMSS) and convert to start time to unix... (8 Replies)
Discussion started by: hotbaws11
8 Replies
8. What is on Your Mind?
WOW, just WOW...
It would be mighty interesting to see shell code translated to this. Kudos to the young guy who succeeded...
'https://spectrum.ieee.org/tech-talk/computing/software/classical-chinese?fbclid=IwAR25BRl8ezV4MkiYILJM-zT3_iN4fOu7cq-CkmhN5205YyVXO-IGmXJKiGA'
Deliberately put... (3 Replies)
Discussion started by: wisecracker
3 Replies
DATE(1) BSD General Commands Manual DATE(1)
NAME
date -- display or set date and time
SYNOPSIS
date [-ajnu] [-d date] [-r seconds] [+format] [[[[[[CC]yy]mm]dd]HH]MM[.SS]]
DESCRIPTION
date displays the current date and time when invoked without arguments. Providing arguments will format the date and time in a user-defined
way or set the date. Only the superuser may set the date.
The options are as follows:
-a Use adjtime(2) to change the local system time slowly, maintaining it as a monotonically increasing function. -a implies -n.
-d date
Parse the provided human-described date and time and display the result without actually changing the system clock. (See
parsedate(3) for examples.)
-j Parse the provided canonical representation of date and time (described below) and display the result without actually changing the
system clock.
-n The utility timed(8) is used to synchronize the clocks on groups of machines. By default, if timed is running, date will set the
time on all of the machines in the local group. The -n option stops date from setting the time for other than the current machine.
-r seconds
Print out the date and time that is seconds from the Epoch.
-u Display or set the date in UTC (universal) time.
An operand with a leading plus (+) sign signals a user-defined format string which specifies the format in which to display the date and
time. The format string may contain any of the conversion specifications described in the strftime(3) manual page, as well as any arbitrary
text. A <newline> character is always output after the characters specified by the format string. The format string for the default display
is:
%a %b %e %H:%M:%S %Z %Y
If an operand does not have a leading plus sign, it is interpreted as a value for setting the system's notion of the current date and time.
The canonical representation for setting the date and time is:
CC The first two digits of the year (the century).
yy The second two digits of the year. If yy is specified, but CC is not, a value for yy between 69 and 99 results in a CC value
of 19. Otherwise, a CC value of 20 is used.
mm The month of the year, from 01 to 12.
dd The day of the month, from 01 to 31.
HH The hour of the day, from 00 to 23.
MM The minute of the hour, from 00 to 59.
SS The second of the minute, from 00 to 61.
Everything but the minutes is optional.
Time changes for Daylight Saving and Standard time and leap seconds and years are handled automatically.
ENVIRONMENT
The following environment variables affect the execution of date:
TZ The timezone to use when displaying dates. See environ(7) for more information.
FILES
/etc/localtime Symlink pointing to system's default timezone information file in /usr/share/zoneinfo directory.
/var/log/wtmp A record of date resets and time changes.
/var/log/messages A record of the user setting the time.
EXAMPLES
The command:
date '+DATE: %m/%d/%y%nTIME: %H:%M:%S'
will display:
DATE: 11/21/87
TIME: 13:36:16
The command:
date 8506131627
sets the date to ``June 13, 1985, 4:27 PM''.
The command:
date 1432
sets the time to 2:32 PM, without modifying the date.
DIAGNOSTICS
Exit status is 0 on success, 1 if unable to set the date, and 2 if able to set the local date, but unable to set it globally.
Occasionally, when timed(8) synchronizes the time on many hosts, the setting of a new time value may require more than a few seconds. On
these occasions, date prints: 'Network time being set'. The message 'Communication error with timed' occurs when the communication between
date and timed fails.
SEE ALSO
adjtime(2), gettimeofday(2), settimeofday(2), parsedate(3), strftime(3), utmp(5), timed(8)
R. Gusella and S. Zatti, TSP: The Time Synchronization Protocol for UNIX 4.3BSD.
STANDARDS
The date utility is expected to be compatible with IEEE Std 1003.2 (``POSIX.2'').
BSD
November 15, 2006 BSD