Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

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

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-09-2017
fspalero fspalero is offline
Registered User
 
Join Date: Jul 2001
Last Activity: 3 May 2017, 2:19 AM EDT
Location: Manila Philippines
Posts: 50
Thanks: 1
Thanked 0 Times in 0 Posts
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:
sed searches a character string for a specified delimiter character, and returns a leading or traili 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. Linux 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 02:29 AM..
Sponsored Links
    #2  
Old Unix and Linux 01-09-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 May 2017, 10:04 PM EDT
Location: San Jose, CA, USA
Posts: 10,296
Thanks: 519
Thanked 3,583 Times in 3,051 Posts
Quote:
Originally Posted by fspalero View Post
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:
sed searches a character string for a specified delimiter character, and returns a leading or traili 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. Linux 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.
Your requirements are not at all clear. The sample text file and sample output file you have shown seem to want to replace the 2nd double quoted string between vertical bar field separators with a double quoted single <space> character.

But your description says that you want to search a "character string for a specified delimiter character, and returns a leading or trailing space/blank". It doesn't say anything about replacing anything; it just requests that a leading or trailing <space> or <tab> character be returned if some unspecified single delimiter character is found.

Please clearly explain what you are trying to do AND show us (in CODE tags) what you have a tried to meet these requirements on your own.

Last edited by Don Cragun; 01-09-2017 at 05:10 AM.. Reason: Include dropped quote.
Sponsored Links
    #3  
Old Unix and Linux 01-09-2017
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 23 May 2017, 10:50 PM EDT
Location: Simplicity
Posts: 3,547
Thanks: 277
Thanked 1,181 Times in 1,069 Posts
Assuming you want the 2nd "string" substituted by a " ", and *retain* (preserve) the spaces at the very beginning and end of the line:

Code:
sed 's/"[^"]*"/" "/2' inputfile

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Counting leading spaces to a character SkySmart Shell Programming and Scripting 7 11-27-2014 12:52 PM
Cutting a string using more than one character as delimiter chillblue Shell Programming and Scripting 4 05-31-2013 01:16 PM
insert leading zeroes based on the character count gpaulose Shell Programming and Scripting 3 11-02-2009 09:32 AM
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 06:58 AM
multi character delimiter dr46014 UNIX for Dummies Questions & Answers 7 09-09-2008 01:02 PM



All times are GMT -4. The time now is 12:19 AM.