03-17-2008
SED command ---------help needed
Hi all
I am new babie to shell script, so please advise me n help me .
suppose i have a string "abacus sabre", i need to replace occurences 'ab' with 'cd' and i need to store this result into same string and i need to return this result from script to the calling function, where as the string is passed from calling function.
i tried like this
mainStr="abacus"
old_word="ab"
new_word="cd"
result=`sed -i s/$old_word/$new_word $mainstr `
return $result
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi all,
I need some help with sed command. I'm trying to move all the files with a modified date within 12:00 - 13:00.
What i'm doing here is to do is
ls -lt | grep 'Jun 22 12:' > list.txt
to get all file names within that period.
However how do i strip off
-rw-r--r-- 1 enfoot adi... (2 Replies)
Discussion started by: manualvin
2 Replies
2. Shell Programming and Scripting
Is it possible to process multiple variables in a single sed command?
I have the following ksh with three variables and I want to search for all variables which start with "var" inside input.txt.
I tired "$var$" but it just prints out everyting in input.txt and does not work.
$ more test.ksh... (5 Replies)
Discussion started by: stevefox
5 Replies
3. Shell Programming and Scripting
Hi,
Could you please explain me the below statement -- phrase wise.
sed -e :a -e '$q;N;'$cnt',$D;ba' abc.txt > xyz.txt
if suppose $cnt contains value: 10
it copies last 9 lines of abc.txt to xyz.txt
why it is copying last 9 rather than 10.
and also what is ba and $D over there in... (4 Replies)
Discussion started by: subbukns
4 Replies
4. Shell Programming and Scripting
Hello, I need a smart sed command that can take any of the following two as an input and give below mentioned output. As you can see, I am trying to convert some C code
INPUT:
struct abc_sample1 {
char myString;
UINT16 myValue1;
... (2 Replies)
Discussion started by: SiftinDotCom
2 Replies
5. Shell Programming and Scripting
I have a requirement in my project to create report from a template file.
A sample template file is added below:
The report data is stored in a file. A sample data file is added below:
Using the above template and data file I want to create a report like this:
I have tried to... (1 Reply)
Discussion started by: Alecs
1 Replies
6. UNIX for Dummies Questions & Answers
Hi,
I am splitting a file based on pattern using sed -f command as below:
sed_cmd2 is the Pattern filename which has the below mentioned pattern in it:
#n
/\(.*\) \(.*\) \(mith\).*/w smith
Input file has following data
1 John Smith Chicago
2 Mary Smith New York
3 Judy... (2 Replies)
Discussion started by: 12345
2 Replies
7. Shell Programming and Scripting
I want to execute below command using line number as a variable.
sed '5c\ disk = jskdjfdsk' vm.cfg
How do i substitute a variable in place of 5
for example
i tried substituting
sed '$variablec\ disk = jskdjfdsk' vm.cfg
and
sed '"$variable"c\ disk = jskdjfdsk' vm.cfg)
but they... (2 Replies)
Discussion started by: pinga123
2 Replies
8. Shell Programming and Scripting
vif =
I need to replace "00:16:3E:64:FB:D3" to a new mac address value from below mentioned file.
# cat vm.cfg
acpi = 1
apic = 1
builder = 'hvm'
device_model = '/usr/lib/xen/bin/qemu-dm'
disk =
kernel = '/usr/lib/xen/boot/hvmloader'
memory = '300'
name = 'vm_temp'
on_crash =... (1 Reply)
Discussion started by: pinga123
1 Replies
9. Shell Programming and Scripting
Hi all,
What am I doing wrong here?
$ cat test_sed.ksh
#!/usr/bin/ksh
var="sed -e \'6s/9/6/\' testfile.txt > testfile.txt.2"
$var
$ ./test_sed.ksh
sed: command garbled: \'6s/9/6/\'
Thank you! (4 Replies)
Discussion started by: ejianu
4 Replies
10. Shell Programming and Scripting
Hi I have a file that contains lines starting with a particular string plus a Colon: I need to output all these lines but only what comes after the colon
Can you pelase assist?
Example of lines in the file:
com.ubs.f35.cashequities/cashequities: 1 2
... (5 Replies)
Discussion started by: mnassiri
5 Replies
exit(1) User Commands exit(1)
NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps
SYNOPSIS
sh
exit [n]
return [n]
csh
exit [ ( expr )]
goto label
ksh
*exit [n]
*return [n]
DESCRIPTION
sh
exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of
the last command executed (an EOF will also cause the shell to exit.)
return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe-
cuted.
csh
exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the
expression expr.
The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches
for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to
jump to a label that occurs between a while or for built-in command and its corresponding end.
ksh
exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8
bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing
a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit
except for a shell which has the ignoreeof option (See set below) turned on.
return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the
least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return
is invoked while not in a function or a '.' script, then it is the same as an exit.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5)
SunOS 5.10 15 Apr 1994 exit(1)