delete delimiter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete delimiter
# 1  
Old 09-17-2011
delete delimiter

Hi All,

I wanted to replace | to space from 3rd occurence onwards:
I Used below:

Code:
echo "a|b|c|d|e" |sed 's/\|/ /3/g'
Got output:
a|b|c d|e

Code:
expecting Output:
a|b|c d e

# 2  
Old 09-17-2011
Code:
echo "a|b|c|d|e" |sed 's/|/ /3g'

--ahamed
# 3  
Old 09-17-2011
Ahamed,

getting output as below
a b c d e
Code:
expecting Output:
a|b|c d e

# 4  
Old 09-17-2011
I am getting it correctly

Code:
root@bt:/tmp# echo "a|b|c|d|e" |sed 's/|/ /3g'
a|b|c d e

Please check if you missed the 3

--ahamed
# 5  
Old 09-17-2011
Code:
echo "a|b|c|d|e" |sed 's/|/ /3g'
a b c d e

this is in HP-UX
# 6  
Old 09-17-2011
Using awk... ugly though!
Code:
echo "a|b|c|d|e" | awk -F"|" '{ for(i=1;i<=NF;i++){_1=(i<3)?"|":OFS; printf $i _1} }'

--ahamed

---------- Post updated at 12:09 PM ---------- Previous update was at 12:03 PM ----------

Quote:
Originally Posted by Jairaj
Code:
echo "a|b|c|d|e" |sed 's/|/ /3g'
a b c d e

this is in HP-UX
thats weird! Smilie

--ahamed
# 7  
Old 09-17-2011
Thanks Ahamed.
Awk command is working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Rsync with --delete but do not delete peer dirs on target

rsync with --delete won't honor the delete if the source is something/*. I want the delete to work, but not to delete directories on the target that are peer to the intended directory. For example, using these source and target file structures: Source on desktop: ~/ Money/ ... (4 Replies)
Discussion started by: JavaMeister
4 Replies

2. Programming

Mismatched free() / delete / delete [] line no missing

Could you tell me the possibilities of the reason to get the Mismatched free() / delete / delete . I unable to see the line no in the valgrind report. it displays the function name. with that function name, I am not able to find where exactly the issue is there.I am getting the Mismatched free()... (3 Replies)
Discussion started by: SA_Palani
3 Replies

3. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

4. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

5. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

6. Shell Programming and Scripting

how to get everything before the last delimiter?

hi all, i have a string with a number of "/"s as delimiter. and i want everything BEFORE the last delimiter i know to use basename to get everything after the last delimiter. thx a lot! (2 Replies)
Discussion started by: sunnydanniel
2 Replies

7. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

8. Shell Programming and Scripting

Help regarding the delimiter

Hi, I am trying to load data from a file to oracle DB. The file am using has a ";" as a delimiter. While I load the file, I want to check whether the file is having the correct delimiter or not. if not, the file should not be processed. Is there any way that i could handle this scenario using... (3 Replies)
Discussion started by: smileyreddy
3 Replies

9. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

10. Shell Programming and Scripting

delete a field along with delimiter in the whole file

I have file with 20 fields and its pipe delimiter. I need to remove the 18th field along with pipe delimiter that seperates 17th and 18th field. In turn that means i want to make it now a file with only 19 fields. Can some body let me know how ican remove the 18th field from the whole file? (5 Replies)
Discussion started by: dsravan
5 Replies
Login or Register to Ask a Question