Need help on find and replacement on specific line and position


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help on find and replacement on specific line and position
# 36  
Old 01-30-2014
I would have thought this would be obvious by now, but:
Code:
$5=rot($5)

replaces the 5th field with every alphanumeric character (starting at the beginning of the field through the end of the field) rotated.
Code:
$5=rot($5,1,4)

replaces the 5th field with up to 4 alphanumeric characters starting in position 1 rotated.
Code:
$5=rot($5,3)

replaces the 5th field with every alphanumeric character starting in position 3 (to the end of the field) rotated (as in example 3). And,
Code:
$5=rot($5,3,2)

replaces the 5th field with up to 2 alphanumeric characters starting in position 3 rotated (as in example 4).
This User Gave Thanks to Don Cragun For This Post:
# 37  
Old 01-30-2014
I tried it

Example3:

Code:
$5=rot($5,3)

Code:
Input:
AILLIAM
Output:
OORZN

Starting from 3 , it converts everything but first two fields got removed


Example4:

Code:
$5=rot($5,2,3)



Code:
Input:
AILLIAM
Output:
ROLIAM

first letter is missing and then it converts only 2 letter (2 and 3)
# 38  
Old 01-30-2014
In Chubler_XL's function rot(), change the line:
Code:
   for(i=start;i<=length(string);i++) {

to:
Code:
   for(i=length(string);i;i--) {

This User Gave Thanks to Don Cragun For This Post:
# 39  
Old 01-30-2014
Quote:
Originally Posted by Don Cragun
In Chubler_XL's function rot(), change the line:
Code:
   for(i=start;i<=length(string);i++) {

to:
Code:
   for(i=length(string);i;i--) {

i changed it

$5=rot($5,2,3)

Input :

03079

output :

97960

what i'm expecting

06929
# 40  
Old 01-30-2014
I have been fighting a losing battle with the flu. I didn't realize it had affected my ability to read and write code. Please accept my humble apologies.

The arguments to Chubler_XL's rot() function are:
Code:
rot(string_to_process, starting_position, ending_position)

where starting_position and ending_position are offsets in string (with offset 1 being the 1st character in string). If ending_position is not supplied, it defaults to the offset of the last character in string. If neither starting_position nor ending_position are supplied, rot() acts on every character in string.

The call to rot() for your example 3 is still:
Code:
$5-rot($5,3)

but the call to rot() for your example 4 should be:
Code:
$5=rot($5,2,4)

And, change my earlier (mistaken) fix to Chubler_XL's code to be:
Code:
   for(i=1;i<=length(string);i++) {

Sorry.

I'm going back to bed.
This User Gave Thanks to Don Cragun For This Post:
# 41  
Old 01-31-2014
thanks a lot don cragun.. hope u recovered from flu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. Shell Programming and Scripting

Remove line break at specific position

Hi, I need to remove line breaks from a file, but only the ones at specific position. Input file: this is ok this line is divided at posit ion 30. The same as this one, also position 30 the rest of lines are ok with different lengths The longest ones are always s plitted at same... (15 Replies)
Discussion started by: qranumo
15 Replies

3. Shell Programming and Scripting

Find and replace with 0 for characters in a specific position

Need command for position based replace: I need a command to replace with 0 for characters in the positions 11 to 20 to all the lines starts with 6 in a file. For example the file ABC.txt has: abcdefghijklmnopqrstuvwxyz 6abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz... (4 Replies)
Discussion started by: thangabalu
4 Replies

4. Shell Programming and Scripting

How to concatene files and put each line of files on a specific position ?

Hi, I have some files that i want to concatene and put each of lines of this files on a specific position : File1 AAAAAAA BBBBBBB CCCCCCC File2 DDDDDDD EEEEEEE FFFFFFF File3 GGGGGG HHHHHH IIIIII New file (6 Replies)
Discussion started by: apippo70
6 Replies

5. Shell Programming and Scripting

Printing characters at specific position in line

Hi, I am trying to get an output like : +----------------------------------+ ----------- + + some variable substitution + some text + Is there a way I can specify in printf (in ksh) the particular position I want to print a character, and also repeat a character from... (1 Reply)
Discussion started by: neil.k
1 Replies

6. Shell Programming and Scripting

Find the position of a pattern on a line from a csv file

hello I'm doing a unix program and i'm using many file csv.in each csv file the colums are separated by ";" I would like to know the position of a pattern. For example for a line yyyy, bbbb, cccc; ddddd;eeee. I will like for example by finding the position of the pattern "cccc" and the response is... (6 Replies)
Discussion started by: papis
6 Replies

7. Shell Programming and Scripting

Search in specific position and print the whole line

I have two files abc.dat and sant.dat (Big file 60k rows) for every line's 1,4 of abc.dat need to seach if this is present on 28,4 of sant.dat every line. if its present the output needs to go to bde.dat Example: contents abc.dat aaaa bbbb cccc dddd contents sant.dat this is... (4 Replies)
Discussion started by: ssantoshss
4 Replies

8. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

9. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

10. Shell Programming and Scripting

check position of end of line for some specific lines

-------------------------------------------------------------------------------- Have to check in a file that the lines starting with 620 and 705 are ending at same posiotin. 82012345 62023232323 70523949558 62023255454 9999 In the above lines, i have to check the lines starting... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question