Sponsored Content
Top Forums Shell Programming and Scripting Replace nth to nth character? Post 302949528 by Aia on Sunday 12th of July 2015 07:25:42 PM
Old 07-12-2015
Code:
sed 's/\(.\{16\}\).\{16\}/\1AAAAAAAA/' file

The cat command is not necessary since sed can read a file on its own.
The red part is matching another 16 characters, and when you \1 those 16 matched chars are discarded and replaced by AAAAAAAA.
Code:
sed 's/\(.\{16\}\).\{8\}/\1AAAAAAAA/' file

The red part has to be the same length of the substitution if you do not want to truncate the original line any farther.

---------- Post updated at 05:25 PM ---------- Previous update was at 05:02 PM ----------

You can do it with many other programs, however I prefer Perl.

Code:
perl -pe 'substr($_, 16, length "AAAAAAAA") = "AAAAAAAA"' file

4040AB50025D8843AAAAAAAA0000E5020046904444047FD76A029E8009E8B387C19C7FA44E2842B1D6229383502608435A552D1A5D...


Last edited by Aia; 07-12-2015 at 08:45 PM..
This User Gave Thanks to Aia For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I get the nth character from a string?

How to I get the nth character from a string in shell script. For instance, I have a string London. I want to get, say the first character (L) from the string. How do I do this in unix shell? Thankx (4 Replies)
Discussion started by: toughman
4 Replies

2. UNIX for Dummies Questions & Answers

Replace nth character in a file with a period

Hi all, If you look at the example below,I want to replace the 21st character (,) with a period (.). I have 1000 records in a file can someone help me how to do that. Thankyou all in advance. "2008-07-15... (3 Replies)
Discussion started by: blackhawk_123
3 Replies

3. Shell Programming and Scripting

Using AWK to find top Nth values in Nth column

I have an awk script to find the maximum value of the 2nd column of a 2 column datafile, but I need to find the top 5 maximum values of the 2nd column. Here is the script that works for the maximum value. awk 'BEGIN { subjectmax=$1 ; max=0} $2 >= max {subjectmax=$1 ; max=$2} END {print... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

4. Shell Programming and Scripting

Calculating average for every Nth line in the Nth column

Is there an awk script that can easily perform the following operation? I have a data file that is in the format of 1944-12,5.6 1945-01,9.8 1945-02,6.7 1945-03,9.3 1945-04,5.9 1945-05,0.7 1945-06,0.0 1945-07,0.0 1945-08,0.0 1945-09,0.0 1945-10,0.2 1945-11,10.5 1945-12,22.3... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

5. Emergency UNIX and Linux Support

Replace nth position character of all the lines in file

I want to replace 150th character of all the lines in a file using sed or awk... searched the forums but didn't find exact answer (9 Replies)
Discussion started by: greenworld123
9 Replies

6. Shell Programming and Scripting

[Solved] Find and replace till nth occurence of a special character

Hi, I have a requirement to search for a pattern in each line in a file and remove the in between words till the 3rd occurrence of double quote ("). Ex: CREATE TABLE "SCHEMANAME"."AMS_LTV_STATUS" (Note: "SCHEMANAME" may changes for different schemas. Its not a fixed value) I need to... (2 Replies)
Discussion started by: satyaatcgi
2 Replies

7. Shell Programming and Scripting

To find nth position of character in string

Hi guyz i want to know nth position of character in string. For ex. var="UK,TK,HK,IND,AUS" now if we see 1st occurance of , is at 3 position, 2nd at 6,..4th at 13 position. 1st position we can find through INDEX, but what about 2nd,3rd and 4th or may be upto nth position. ? In oracle we had... (2 Replies)
Discussion started by: Jonty Immortal
2 Replies

8. Shell Programming and Scripting

awk script to replace nth character with comma

I have a requirement as below. In one of my column, I have data which may or may not be separted with coma always. Now I need to validate the length of these text within the coma (if available) and if the length is more than 30 characters, I need to insert a coma either at 30 characters if its... (3 Replies)
Discussion started by: aramacha
3 Replies

9. Shell Programming and Scripting

Replace a value of Nth field of nth row

Using Awk, how can I achieve the following? I have set of record numbers, for which, I have to replace the nth field with some values, say spaces. Eg: Set of Records : 4,9,10,55,89,etc I have to change the 8th field of all the above set of records to spaces (10 spaces). Its a delimited... (1 Reply)
Discussion started by: deepakwins
1 Replies

10. Post Here to Contact Site Administrators and Moderators

How to read the nth character from the line.?

I have Index Line and I tried to get the 9th character from the file and to check the character is "|" or not. Shell Scripting. Sample Index file. "91799489|K8E|188.004.A.917994892.1099R.c.01.pdf|2013|10/15/2014|002|B|C|C"... (3 Replies)
Discussion started by: pavand
3 Replies
StringBrowser(3I)					    InterViews Reference Manual 					 StringBrowser(3I)

NAME
StringBrowser - browse and/or select items in a list SYNOPSIS
#include <InterViews/strbrowser.h> DESCRIPTION
StringBrowser is an interactor that provides a browsing and selection interface to a list of strings. StringBrowsers are often used in dialog boxes to let the user browse and select from an unbounded set of textual entries. A StringBrowser displays the list of strings and provides several ways to scroll the list. The user selects strings with either the mouse or the keyboard; the StringBrowser can restrict selection to a single string or allow multiple selections. The application queries the StringBrowser for the selected string(s). A StringBrowser contains no entries initially; strings are appended consecutively or in random order, and they can be removed in any order. The strings are accessed with a string index from 0 to n-1, where n is the total number of strings. The StringBrowser maintains a sepa- rate list of strings that have been selected; these strings are accessed with a selection index from 0 to m-1, where m is the total number of selected strings. Left-clicking inside the StringBrowser (or calling the Browse function) makes it interpret subsequent keyboard events as scrolling or selection operations on the entries. StringBrowser relinquishes control when it detects a click outside its canvas or when it receives a predetermined escape character. Middle-clicking inside the StringBrowser lets the user ``grab-scroll'' the entries. During grab-scrolling, the StringBrowser scrolls the entries to follow the mouse position, making it appear as though the user is dragging the entries themselves. Right-clicking engages ``rate-scrolling,'' a joy-stick-like scrolling interface in which the scrolling rate increases as the user drags the mouse away from the initial click point. For example, dragging the mouse downwards after the initial click scrolls the browser downwards at an increasing rate; dragging upwards thereafter reduces the rate until scrolling stops entirely at the initial click point. Dragging up beyond this point makes the browser scroll in the reverse direction. KEY BINDINGS
Below are the key bindings for browsing and selection commands: g Go to the first string. G Go to the last string. a Select all. DEL or BS Unselect all. p Select previous string. n Select next string. < Select topmost-visible string. > Select bottommost-visible string. j Scroll down one string. k Scroll up one string. SPACE Scroll down one screenful. b Scroll up one screenful. d Scroll down one-half screenful. u Scroll up one-half screenful. PUBLIC OPERATIONS
StringBrowser(ButtonState*, int rows, int cols, boolean uniqueSel, int highlight, const char* done) StringBrowser(const char* name, ButtonState*, int, int, boolean, int, const char*) Create a new StringBrowser object. The StringBrowser will use the ButtonState to communicate the result of browsing operations. The StringBrowser bases its shape on the rows and cols parameters: the height equals rows multiplied by the font height, and the width equals cols multiplied by the width of an average character. The uniqueSel parameter specifies whether or not selection is limited to one string (the default), and the highlight parameter specifies the appearance of selected strings (Reversed by default). Typing any character in the string done will make the StringBrowser stop interpreting keyboard events; the ButtonState is set to this terminating character as a side-effect. A double left-click inside the StringBrowser is equivalent to a single left-click selection followed by a key press that generates the first character in done. To be interpreted as a double-click, two clicks must occur not more than clickDelay milliseconds apart. The default click delay is 250 ms; a different value can be specified via the "clickDelay" user-preference attribute. void Browse() Initiate browsing. Subsequent keypresses will be interpreted as browsing and selection commands according to the key bindings listed above. void Insert(const char* string, int index) Insert string at position index. StringBrowser makes a copy of the string for internal use. void Replace(const char* string, int index) Replace the string at position index with string. StringBrowser makes a copy of the string for internal use. This operation does nothing if the index supplied is not valid. void Append(const char* string) Insert a copy of string after the last string. void Remove(int index) Remove the string at position index, moving subsequent strings up to fill the gap. int Index(const char* string) Return the index of the first string that matches string. char* String(int index) Return the string at the given index. int Count() Return the total number of strings in the StringBrowser. void Clear() Remove all strings from the StringBrowser. void Select(int index) void Unselect(int index) Select (unselect) the string at the given index. The string will be redrawn in the appropriate style. If multiple selections are not allowed and an another string has been selected already, then selecting a new string will unselect the original string. void SelectAll() void UnselectAll() Select (unselect) all strings. SelectAll does nothing if multiple selections have been disallowed. int Selection(int n) Return the string index of the nth selected string. int SelectionIndex(int n) Return the selection index of the nth string. int Selections() Return the total number of selected strings. boolean Selected(int n) Return whether the nth string has been selected. SEE ALSO
Interactor(2I), Button(3I) InterViews 30 November 1989 StringBrowser(3I)
All times are GMT -4. The time now is 03:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy