Sponsored Content
Full Discussion: Sed capture help
Top Forums Shell Programming and Scripting Sed capture help Post 302518354 by ddreggors on Friday 29th of April 2011 11:37:05 AM
Old 04-29-2011
Also note that Ahamed did not use a 'g' at the end of the regex search/replace. In this situation (mine included) the g is not needed.

Here is why:

With a match like we have '(.*)\/(.*)' we would match the whole line. Everything before the '/' and everything after.

Now take the following line:

ABC123ABC456ABC

if sed matches ABC and replaces it with XYZ but does not use the g command (sed 's/ABC/XYZ/') only the first ABC would be replaced.

Examples:
Code:
$ echo "ABC123ABC456ABC" |sed 's/ABC/XYZ/'
XYZ123ABC456ABC
$ echo "ABC123ABC456ABC" |sed 's/ABC/XYZ/g'
XYZ123XYZ456XYZ

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

capture the ouput!

Hi, my perl script is calling another external java program. The Java in turn prints out a string. how can I capture the string. ------------------ #!/usr/bin/perl print "Content-type:text/html\n\n"; use CGI; $query = new CGI; $theCookie = $query->cookie('someCookie'); $user =... (0 Replies)
Discussion started by: azmathshaikh
0 Replies

2. AIX

Capture IP Adress

hello I need for a script to capture the ip address from the connected user. I have 5 logical partitions. With "who", i have the ip adress, but only for 2 servers. Do you know another command to know the ip address of connected clients ? thank you (14 Replies)
Discussion started by: pascalbout
14 Replies

3. Shell Programming and Scripting

capture in telnet

I'm trying to capture the files that this command types out, but i'm not able to do it. I'm pipeing everything to the telnet command because if i dont the connection closes. Any suggestions. #!/bin/ksh hostn='x.x.x.xx xxxx' (echo "open $hostn\r" sleep 3 echo " \r" sleep 2 (echo... (3 Replies)
Discussion started by: wisher115
3 Replies

4. Shell Programming and Scripting

capture the file name

I am trying to capture the file name(which is not of fixed length) and put it in a variable. It is working in unix whereas when I am running the same script in Informatica it is not giving me the desired output. But when I comment the option(find the file name) then it is working fine. It can... (4 Replies)
Discussion started by: Mandab
4 Replies

5. Shell Programming and Scripting

How to scan and capture

Hi, I am new to unix. I have a file with records like the below ads-sap-4.txt: </a></b></span><span class="linkbutton yellow_but"><a id="2005754_more" style="cursor:pointer; cursor:hand;"... (3 Replies)
Discussion started by: akondeti
3 Replies

6. Shell Programming and Scripting

Capture of month

Guys I need your help... I receive the month and the day in a file and I keep it in a variable. I need to take this day that Iīve kept compare with the current day and pick the file to the next day... Letīs say I receive a file 27-JUL-2007 and I need to check in the system the current day and... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies

7. Shell Programming and Scripting

script to capture

Hi In my production server some user runnig some scripts to get some data. I need a script to capture this user script code. best rds ab (5 Replies)
Discussion started by: aboorkuma
5 Replies

8. Programming

how to capture OS name using C/C++ code

Hi, I want to know the os name via c/c++ source code.so please help me to do the same. I will appreciate if anyone can provide me the source code. Thanks in advance.. (9 Replies)
Discussion started by: smartgupta
9 Replies

9. Shell Programming and Scripting

Capture the value between brackets

Hi I am having hard time getting this right and need some help. I Have 3 files, and everyone contains the following:- File1 Today, we have Name(Jack) Age(19) Class (A2) Today, we have Name(Kim) Class (G9) File2 Today, we have Name(Lee) Age(19) Class (A2) Today, we have... (8 Replies)
Discussion started by: samsan
8 Replies

10. Shell Programming and Scripting

Using sed to capture the year

Hi, I'm not real familiar with sed, but I need to capture the year this directory path. Here's what I have so far. I'm able to capture the run name, but I want the only the year that's within the run name. How can I do this? ... (3 Replies)
Discussion started by: jdilts
3 Replies
SHTOOL-SUBST.TMP(1)					      GNU Portable Shell Tool					       SHTOOL-SUBST.TMP(1)

NAME
shtool-subst - GNU shtool sed(1) substitution operations SYNOPSIS
shtool subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup ext] [-e|--exec cmd] [-f|--file cmd-file] [file] [file ...] DESCRIPTION
This command applies one or more sed(1) substitution operations to stdin or any number of files. OPTIONS
The following command line options are available. -v, --verbose Display some processing information. -t, --trace Enable the output of the essential shell commands which are executed. -n, --nop No operation mode. Actual execution of the essential shell commands which would be executed is suppressed. -w, --warning Show warning on substitution operation resulting in no content change on every file. The default is to show a warning on substitution operations resulted in no content change on all files. -q, --quiet Suppress warning on substitution operation resulting in no content change. -s, --stealth Stealth operation. Preserve timestamp on file. -i, --interactive Enter interactive mode where the user has to approve each operation. -b, --backup ext Preserve backup of original file using file name extension ext. Default is to overwrite the original file. -e, --exec cmd Specify sed(1) command directly. -f, --file cmd-file Read sed(1) command from file. EXAMPLE
# shell script shtool subst -i -e 's;(c) ([0-9]*)-2000;(c) 1-2001;' *.[ch] # RPM spec-file %install shtool subst -v -n -e 's;^(prefix=).*;1 $RPM_BUILD_ROOT%{_prefix};g' -e 's;^(sysconfdir=).*;1 $RPM_BUILD_ROOT%{_prefix}/etc;g' `find . -name Makefile -print` make install HISTORY
The GNU shtool subst command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 2001 for GNU shtool. It was prompted by the need to have a uniform and convenient patching frontend to sed(1) operations in the OpenPKG package specifications. SEE ALSO
shtool(1), sed(1). 18-Jul-2008 shtool 2.0.8 SHTOOL-SUBST.TMP(1)
All times are GMT -4. The time now is 08:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy