sed to insert a separator


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to insert a separator
# 1  
Old 01-17-2011
sed to insert a separator

My txt file consists of records with 6 numbers followed by 3 characters.
Is there a simple “sed” which will insert a | separator between the 6th and 7th position ?
Many thanks
# 2  
Old 01-17-2011
Code:
sed 's/ /|/6' yourfile

How does your input file look like ? pls provide a sample of input and expect output


depending on what you want to do

Code:
# echo '1 2 3 4 5 6 a b c' | sed 's/ /|/6'
1 2 3 4 5 6|a b c
# echo '123456ABC' | sed 's/^....../&|/'
123456|ABC
# echo '123456ABC' | sed 's/...$/|&/'
123456|ABC
#


Last edited by ctsgnb; 02-11-2011 at 09:33 AM..
# 3  
Old 01-17-2011
Code:
sed -e 's/^....../&|/'

# 4  
Old 02-11-2011
sed to insert a separator

Merci ctsgnb
Thanks M D
Working fine now !
Sorry for the delay in getting back to you : illness & vacation
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed multilines + separator confusion !!

Hi Seders, i am new to this forum, but i think it's quite the best place to post. So, here is my pb : I have a csv file, with comma separator and text enclosed by ". First pb is with text in " ......... ", wich sometimes includes lines break, and commas And to complicate a little more,... (4 Replies)
Discussion started by: yogeek
4 Replies

2. Shell Programming and Scripting

sed to insert a character

Hi all, I have a file like this Q8N302 21-84 Q8N157 15-45 Q99996 167-201 202-251 269-318 I want to insert a character or space if the line starts with a number and I used the command sed 's/^/#/' But in the output file, when it inserts this character, first digit in the number is... (2 Replies)
Discussion started by: kaav06
2 Replies

3. Shell Programming and Scripting

Insert text using sed

sed 's/$/TEST/g' will insert TEST at the end of each line. i want to insert TEST at column 64 (7 Replies)
Discussion started by: lawsongeek
7 Replies

4. Shell Programming and Scripting

sed - insert two lines

I have done this sed command to insert one line after a specific string is found: sed '/patternstring/ a\ new line string' file1 But how do I insert two lines? This is not possible: sed '/patternstring/ a\ new line string \a new line string 2' file1 (2 Replies)
Discussion started by: locoroco
2 Replies

5. Shell Programming and Scripting

Sed find and insert

Hi All I'm trying to insert a pattern if a pattern is found in a file. This is my sample file "PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|25 "PDA"|"Celvin"|"PRJ_AB"|"Completion_Units"|250 I would like to output as "PDA"|"Celvin"|"PRJ_NA"|"Completion_Units"|"Done"|25... (3 Replies)
Discussion started by: Celvin VK
3 Replies

6. UNIX for Dummies Questions & Answers

Sed - Get Separator From String

Hi All, I have the following data in a korn shell variable: a="FirstValue|SecondValue|ThirdValue" The value between "FirstValue", "SecondValue" and "ThirdValue" can change, in this case is a comma: "," and I need to print it only once. I need to know what is the separator value. I... (3 Replies)
Discussion started by: felipe.vinturin
3 Replies

7. Shell Programming and Scripting

Trying to change date separator with sed

Hi there I am trying to convert some date seperators in a large newline delimited file. each line i am interested in has a date in the format 27/05/2009 all I want is to convert the slashes to tildes(~) I have come up with the following code but it does nothing. sed... (5 Replies)
Discussion started by: RadRod
5 Replies

8. Shell Programming and Scripting

sed: how to insert tab?

Hi, I'm using the following to insert lines into file: sed ${rowNr}i'\ first row\ second row\ third row\ ' file.txt How can I add tab in front of each added line? "\t" or actual TAB does not seem to work? Thanks! (2 Replies)
Discussion started by: Juha
2 Replies

9. UNIX for Dummies Questions & Answers

Insert Text With Sed

Hello. Trying to insert text at line 1 and after last line of file. I have searched posts but nothing seems to work. I keep getting extra characters error or nothing gets inserted into the file. #!/bin/sh touch textfile.txt sed 'i\ Add this line before every line with WORD' textfile.txt ... (5 Replies)
Discussion started by: steveramsey
5 Replies

10. Shell Programming and Scripting

sed search and insert

how can i modify a file using sed when searching for a pattern and insert newline after the pattern? pattern example: $ ...(any characters)...$ $ may082001.../tmp/msg.001,,$ REPT CLEAR ALARMS ON UNIT 1 $ may082001.../tmp/msg.002,,$ UNIT 1 IN SERVICE into: $... (1 Reply)
Discussion started by: apalex
1 Replies
Login or Register to Ask a Question