Sponsored Content
Top Forums Shell Programming and Scripting sed searches a character string for a specified delimiter character, and returns a leading or traili Post 302989128 by fspalero on Monday 9th of January 2017 12:55:53 AM
Old 01-09-2017
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 :
Code:
  "1"|"ExternalClassDEA519CF5"|"Art1"
  "2"|"ExternalClass563EA516C"|"Art3"
  "3"|"ExternalClass305ED16B8"|"Art9"
  ...
  ...

Output file :
Code:
  "1"|" "|"Art1"
  "2"|" "|"Art3"
  "3"|" "|"Art9"
  ...
  ...

Thanks in advance.

Regards,
FSPalero

Moderator's Comments:
Mod Comment The last time you got one of these infractions, the note:
Quote:
Repeated refusal to use CODE tags when presenting sample input, sample output, and code segments has resulted in this user being placed in read-only mode for a while.

Continued refusal to properly format posts may result in a permanent ban from this site.To keep the forums high quality for all users, please take the time to format your posts correctly.
was included in your post when tags were added for you. And you still refuse to make any attempt to format your posts. Smilie This is your last warning, the next post from you that includes untagged sample input, sample output, or code segments will result in you being permanently banned from this site.

Last edited by Don Cragun; 01-09-2017 at 03:29 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace first character of string sed

I want to change the first/or any character of a string to upper-case: String: test Desired results: Test or tEst or teSt or tesT thanks (6 Replies)
Discussion started by: prkfriryce
6 Replies

2. Shell Programming and Scripting

Korn: How to loop through a string character by character

If I have a string defined as: MyString=abcde echo $MyString How can I loop through it character by character? I haven't been able to find a way to index the string so that I loop through it. shew01 (10 Replies)
Discussion started by: shew01
10 Replies

3. Shell Programming and Scripting

error while replacing a string by new line character in sed

hi, when i am doing the following things getting error Can anyone please suggest i have a file where there is a line like the following branch=dev sdf dev jin kilii fin kale boyle dev james dev i want to search the existance of dev in the above line. cat "$file" | sed -n... (8 Replies)
Discussion started by: millan
8 Replies

4. Shell Programming and Scripting

Sed to print a string until the second occurrence of a character

Hi, I am totally new to shell scripting. I have a String "c:\working\html\index.txt.12-12-2009.bkp" I want to check if the string has more than one "." character. If it does I would like to retrieve only "c:\working\html\index.txt" i.e, discard the second occurrence of "." and the rest of the... (7 Replies)
Discussion started by: imr
7 Replies

5. 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

6. Shell Programming and Scripting

Find the middle character from a string using sed

Input: qwertmyuiop It should print "m". What's the command to do this with sed? (6 Replies)
Discussion started by: cola
6 Replies

7. Shell Programming and Scripting

Sed is doing my head in! How do you remove the first character of a string?

Hello! Please bare with me, I'm a total newbie to scripting. Here's the sudo code of what I'm trying to do: Get file name Does file exist? If true get length of file name get network id (this will be the last 3 numbers of the file name) loop x 2 If... (1 Reply)
Discussion started by: KatieV
1 Replies

8. 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

9. Shell Programming and Scripting

Sed: delete on each line before a character and after a character

Hi there, A total sed noob here. Is there a way using sed to delete everything before a character AND after another character on each line in a file? The deletion should also delete the indicating characters(here: an opening and a closing parenthesis). The original file would look like... (3 Replies)
Discussion started by: bnbsd
3 Replies

10. Shell Programming and Scripting

Cutting a string using more than one character as delimiter

Hi , I have a set of files in a folder which i need to cut in to two parts.... Sample files touch AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch AE_JUNFOR_2014_YTD_2013-05-30-03-30-02.TXT touch temp_AE_JUNFOR_2014_MTD_2013-05-30-03-30-02.TXT touch... (4 Replies)
Discussion started by: chillblue
4 Replies
wcstok(3)						     Library Functions Manual							 wcstok(3)

NAME
wcstok, wcstok_r - Split wide-character strings into tokens LIBRARY
Standard C Library (libc) SYNOPSIS
wchar_t *wcstok( wchar_t *ws1, const wchar_t *ws2), wchar_t **savept); This prototype conforms to both ISO C and XSH Issue 5 and is strongly recommended for new applications. The wcstok() function supported in compilation environments for XSH versions earlier than XSH Issue 5 does not include the savept parameter, which is required for threadsafe operation. The following proprietary prototype is the threadsafe interface that was supported on Tru64 UNIX versions prior to Version 4.0 and is supported only to provide backward compatibility for applications written before the ISO C and XSH5 threadsafe prototype was avail- able. wchar_t *wcstok_r( wchar_t *ws1, const wchar_t *ws2), wchar_t **savept); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wcstok(): XSH5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Contains a pointer to the wide-character string to be searched. Contains a pointer to the string of wide-character token delimiters. Identifies the location of the wide character where the search for tokens should be started in the next call. The savept parameter contains a pointer to a variable that contains a pointer to the wide character where scanning begins. DESCRIPTION
The wcstok() function splits the wide-character string pointed to by the ws1 parameter into a sequence of tokens, each of which is delim- ited by a wide character from the wide-character string pointed to by the ws2 parameter. Usually, the wcstok() function is called repeatedly to extract the tokens in a wide-character string. On the first call to the wcstok() function, the application sets the ws1 parameter to point to the input wide-character string. The function returns a pointer to the first token. The application program calls the function again with the ws1 parameter set to the null pointer. This call returns a pointer to the next token in the string. The application program repeats the call to wcstok() with the ws1 parameter set to the null pointer until all the tokens in the string have been returned. On the initial call to wcstok(), the function first searches the wide-character string pointed to by the ws1 parameter to locate the first wide character that does not occur in the wide-character delimiter string pointed to by the ws2 parameter. If such a wide character is found, it is the start of the first token. The wcstok() function then searches from there for a wide character that does occur in the delimiter string. If such a wide-character delimiter is found, wcstok() overwrites it with a null wide character, which terminates the cur- rent token. The wcstok() function saves a pointer to the wide character following the null wide character and returns a pointer to the start of the token. In subsequent calls to wcstok(), where ws1 is set to a null pointer, the function starts at the saved pointer and searches for the next wide character that does not occur in the wide-character delimiter string pointed to by the ws2 parameter. If such a wide character is found, it is the start of the new token. The wcstok() function then searches from there for a wide character that does occur in the delim- iter string. If such a wide-character delimiter is found, wcstok() overwrites it with a null wide character, which terminates the new token. The wcstok() function saves a pointer to the wide character following the null wide character and returns a pointer to the start of the new token. It stores the saved pointer in the *savept parameter as well as internally. On calls where the s1 parameter is a null pointer, the function uses the saved pointer in *savept to start searching for the next token. Applications that require threadsafe opera- tion must use a wcstok() interface that includes the savept parameter. If a call to the wcstok() function cannot find a wide character that does not occur in the delimiter string, it returns the null pointer. If a call to the wcstok() function cannot find the terminating wide character that does occur in the delimiter string, the current token extends to the end of the string and subsequent calls to wcstok() return the null pointer. If the delimiters used in the wide-character string change from one set of characters to another within the string, the application can set the second parameter, ws2, to different wide-character strings from call to call. The implementation behaves as though no function calls the wcstok() function. EXAMPLES
The following example splits a wide-character string into tokens: #include <wchar.h> #include <locale.h> #include <stdio.h> #define WLENGTH 40 main() { wchar_t WCString1[WLENGTH], delimiters[WLENGTH]; wchar_t * pwcs; int counter; (void)setlocale(LC_ALL, ""); printf("Enter the string to be searched: "); if (fgetws(WCString1, WLENGTH, stdin) != NULL) { printf("Enter the delimiter(s): "); if (fgetws(delimiters, WLENGTH, stdin) != NULL) { if ((pwcs = wcstok(WCString1, delimiters )) != NULL) { /* pwcs points to the first token */ printf("Token 1 is %S ", pwcs); counter = 2; while ((pwcs = wcstok((wchar_t * )NULL, delimiters )) != NULL) { printf("Token %d is %S ", counter, pwcs); counter++; } } } } } RETURN VALUES
On successful completion, the wcstok() function returns a pointer to the first wide character of a token. A null pointer is returned if there is no token. The wcstok() function also sets the pointer *savept to the wide character from which the search for the next token starts, or to a null pointer if there is none. RELATED INFORMATION
Functions: strtok(3), wcspbrk(3), wcsspn(3), wcstod(3), wcstol(3), wcstoul(3) Standards: standards(5) delim off wcstok(3)
All times are GMT -4. The time now is 06:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy