Sponsored Content
Top Forums Shell Programming and Scripting Replacing one Char in a string of variable length Post 302338290 by nkwilliams on Monday 27th of July 2009 12:48:07 PM
Old 07-27-2009
Replacing one Char in a string of variable length

Hi all,

I am trying to find the best way of making a change to 1 char in a string, the string can be between 1 and 14 characters.

I am reading a line in from a file which contains
012341231231:2:102939283:NNN: Require :NBN:
012838238232:3:372932:NNN: Require :NNB:
I need to change 1 N or a B depending on the number in the 2nd field (a 2 or a 3 in the cases above).

Now each character in the NNN field could initially be N,C,B, or 2 or 3 other characters.

At the moment I can only think of looping around each character using a cut -c to write out each character as it already is then changing the one I want when I get to it, but I was hoping there could be a better and more efficient way.

I am using Redhat Ent 4 with ksh

Thanks in advance

Nigel...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding out the length of a string held within a variable

:confused: Does anyone know which command I can use to find out the length of a string held within a variable? (5 Replies)
Discussion started by: dbrundrett
5 Replies

2. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

3. UNIX for Dummies Questions & Answers

string of 7 char length always...

Hi, I know, particular value in the variable should always be of lenth 7 , but the value that is present in thevariable might be of any no.of characters less than or equal to 7... if the no.of characters in the variable is less than 7, I want to add, zeroes at the starting of the field.. How can... (3 Replies)
Discussion started by: thanuman
3 Replies

4. Programming

replacing char with string

how we can replace char with a string example char *a="a.s" so finally what i ant to do raplace a with ant and s sree so in my array a i want to store the value as "ant.sree" thank u in advance (1 Reply)
Discussion started by: phani_sree
1 Replies

5. Shell Programming and Scripting

Replace variable length numeric string

I have a customer who logged some cc and bank account numbers in their apache logs. I got the cc numbers x'd out with sed -e 's/args=\{16\}/args=XXXXXXXXXXXXXXXX/g' -e 's/cardnum=\{16\}/cardnum=XXXXXXXXXXXXXXXX/g'but that wasn't too difficult due to the value being 16 digits. The bank account... (7 Replies)
Discussion started by: mk4mzid
7 Replies

6. Programming

How to find length of string and pass into char array in C?

Hi All I want to take a Hexadecimal number as input and i want to find lenth of the input and pass it to char s ( char s ). I have a program to convert hexadecial to binary but it is taking limited input but i want to return binary number based on input. How? (1 Reply)
Discussion started by: atharalikhan
1 Replies

7. Shell Programming and Scripting

Match and variable length string

Hello all, source file looks like this: cat toto.txt NAME) VAR1=tata OPT4=toto USER=blabla TZ=/usr/share/zoneinfo/Hongkong OTHEROPT=something ;; NAME2) VAR1=tata OPT4=toto USER=blabla TZ=/usr/share/zoneinfo/Hongkong SOMETHING=else ... (5 Replies)
Discussion started by: maverick72
5 Replies

8. Shell Programming and Scripting

Extracting substrings from a string of variable length

I have a string like Months=jan feb mar april x y .. Here the number of fields in Months is not definite I need to extract each field in the Months string and pass it to awk . Don't want to use for in since it is a loop . How can i do it (2 Replies)
Discussion started by: Nevergivup
2 Replies

9. UNIX for Advanced & Expert Users

Replacing string length based on pattern

Hi All, I have a file which is like below. I need to read all the patterns that starts with P and then replace the 9 digit values to 8 digit values (remove leading integer). Can you please help Example : ( Please look below File) File : P,1 M1,... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

10. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies
PICONV(1)						User Contributed Perl Documentation						 PICONV(1)

NAME
piconv -- iconv(1), reinvented in perl SYNOPSIS
piconv [-f from_encoding] [-t to_encoding] [-p|--perlqq|--htmlcref|--xmlcref] [-C N|-c] [-D] [-S scheme] [-s string|file...] piconv -l piconv -r encoding_alias piconv -h DESCRIPTION
piconv is perl version of iconv, a character encoding converter widely available for various Unixen today. This script was primarily a technology demonstrator for Perl 5.8.0, but you can use piconv in the place of iconv for virtually any case. piconv converts the character encoding of either STDIN or files specified in the argument and prints out to STDOUT. Here is the list of options. Some options can be in short format (-f) or long (--from) one. -f,--from from_encoding Specifies the encoding you are converting from. Unlike iconv, this option can be omitted. In such cases, the current locale is used. -t,--to to_encoding Specifies the encoding you are converting to. Unlike iconv, this option can be omitted. In such cases, the current locale is used. Therefore, when both -f and -t are omitted, piconv just acts like cat. -s,--string string uses string instead of file for the source of text. -l,--list Lists all available encodings, one per line, in case-insensitive order. Note that only the canonical names are listed; many aliases exist. For example, the names are case-insensitive, and many standard and common aliases work, such as "latin1" for "ISO-8859-1", or "ibm850" instead of "cp850", or "winlatin1" for "cp1252". See Encode::Supported for a full discussion. -r,--resolve encoding_alias Resolve encoding_alias to Encode canonical encoding name. -C,--check N Check the validity of the stream if N = 1. When N = -1, something interesting happens when it encounters an invalid character. -c Same as "-C 1". -p,--perlqq Transliterate characters missing in encoding to x{HHHH} where HHHH is the hexadecimal Unicode code point. --htmlcref Transliterate characters missing in encoding to &#NNN; where NNN is the decimal Unicode code point. --xmlcref Transliterate characters missing in encoding to &#xHHHH; where HHHH is the hexadecimal Unicode code point. -h,--help Show usage. -D,--debug Invokes debugging mode. Primarily for Encode hackers. -S,--scheme scheme Selects which scheme is to be used for conversion. Available schemes are as follows: from_to Uses Encode::from_to for conversion. This is the default. decode_encode Input strings are decode()d then encode()d. A straight two-step implementation. perlio The new perlIO layer is used. NI-S' favorite. You should use this option if you are using UTF-16 and others which linefeed is not $/. Like the -D option, this is also for Encode hackers. SEE ALSO
iconv(1) locale(3) Encode Encode::Supported Encode::Alias PerlIO perl v5.16.3 2013-04-29 PICONV(1)
All times are GMT -4. The time now is 02:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy