Sponsored Content
Top Forums Shell Programming and Scripting replace first character of string sed Post 302130203 by kahuna on Friday 3rd of August 2007 02:07:40 PM
Old 08-03-2007
A shell version
Code:
$cat  example
#!/bin/sh
INPUT=test
for COL in 1 2 3 4
do
UPPER=`echo "$INPUT" | cut -c $COL  |tr '[a-z]' '[A-Z]'`
echo "$INPUT" | sed 's/./'$UPPER'/'$COL
done

$./example       
Test
tEst
teSt
tesT
$

Note: sed only will go up to 511 characters

Last edited by kahuna; 08-03-2007 at 03:37 PM.. Reason: Add Caviat
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find and replace character in a string

Hi all, My problem is the following: I've a script that must list all files in a directory and write this information in a text file. I've tried to get the list through ls command and then write it using msgecho msgecho "`ls $PATH_APS_JOB_ORA`" This works good but the created string... (7 Replies)
Discussion started by: callimaco0082
7 Replies

2. Linux

How to replace the 2nd character in a string using sed?

Hi, i have string var1=NN. Based on conditions, i have to change this first N to Y or second N to Y and send the details to other process. How to do that? This is a linux machine. Thanks, Selva (1 Reply)
Discussion started by: bharathappriyan
1 Replies

3. Shell Programming and Scripting

In Sed how can I replace starting from the 7th character to the 15th character.

Hi All, Was wondering how I can do the following.... I have a String as follows "ACCTRL000005022RRWDKKEEDKDD...." This string can be in a file called tail.out or in a Variable called $VAR2 Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Discussion started by: mohullah
5 Replies

4. Shell Programming and Scripting

replace character from string

I have a string ----- i want to replace the 3rd '-' with a character How can i do that Basically im trying to do hangman I have added the '-----' string to a file called hash and i have the character in a variable called $input also i have the character location(index) in this variable... (12 Replies)
Discussion started by: omaral
12 Replies

5. Shell Programming and Scripting

Replace character in certain position in a string

Hello everyone this is my first post of many to come :) I am writing a script and in this script at one point i need to replace a character in a particular position in a string for example: in the string "mystery" i would need to replace the 3rd position to an "r" so the string becomes... (3 Replies)
Discussion started by: snipaa
3 Replies

6. Shell Programming and Scripting

replace a character in a string-help please

I have a string eg. word=promise and I have the masked version of the word which is -------(7dash for each character) if the user input a character O, I want the masked version of the word to be --o---- if the user inputs another character p, then the masked word becomes p-o---- How can i... (1 Reply)
Discussion started by: rajugurung
1 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

How to replace with a special character in String

Hi, I am beginner to Shell Scripting. I have a String like this "testabcdef", i need the first character as it is and the remaining character should be replaced by the the '*' character. e.g(t***********) PLZ Suggest me. (5 Replies)
Discussion started by: nanthagopal
5 Replies

9. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies
Test::XML::Twig(3pm)					User Contributed Perl Documentation				      Test::XML::Twig(3pm)

NAME
Test::XML::Twig - Test XML::Twig handlers SYNOPSIS
use Test::XML::Twig tests => 2; use My::Twig qw( handler ); test_twig_handler( &handler, '<foo/>', '<bar/>', 'turns foo to bar', ); test_twig_handlers( { twig_handlers => { 'foo' => &handler } }, '<foo/>', '<bar/>', 'turns foo into bar', ); DESCRIPTION
This module is for testing XML::Twig handlers. FUNCTIONS
All functions are exported. get_twig ( INPUT [, ARGS ] ) Return a parsed twig of INPUT, or undef on parse failure. Optionally, ARGS may be supplied as a set of hash-like parameters to be passed into the twig constructor. test_twig_handler ( HANDLER, INPUT, EXPECTED, TESTNAME [, COND ] ) Parse INPUT, using HANDLER as a twig_handler (i.e: it gets called after the parse tree has been built). Tests that the result is the same as EXPECTED (which can be either a string of XML or a quoted regex). HANDLER must be a code ref. Optionally, COND can be supplied. Instead of the handler being called with the root element of INPUT, COND will be used with first_child() to select an alternative element. Returns true / false depending upon test success. test_twig_handlers ( ARGS, INPUT, EXPECTED, TESTNAME ) This is similiar to test_twig_handler(), but with more flexibility. The first argument, ARGS, is a hash reference which can be used to specify any of the ordinary parameters to twig's constructor. This lets you test things like start_tag_handlers, as well as multiple twig_handlers together. SEE ALSO
Test::More, Test::XML, XML::Twig. AUTHOR
Dominic Mitchell, <cpan2 (at) semantico.com> COPYRIGHT AND LICENSE
Copyright 2002 by semantico This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2009-07-02 Test::XML::Twig(3pm)
All times are GMT -4. The time now is 04:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy