Insert 1 space using the command sed


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Insert 1 space using the command sed
# 1  
Old 05-10-2012
Insert 1 space using the command sed

Hi

I want to use sed to insert one space after the 10'th character in every line.
The lines are on this format:

Code:
2012-01-1012:30:55|7323456|65432
2011-02-0313:11:06|1223|3456
......
......

Does anyone know sed well enough to acomplish this?
If there is any other way around this without using sed I would also be very thankful.


Moderator's Comments:
Mod Comment Please use code tags, thanks!

Last edited by zaxxon; 05-10-2012 at 05:54 AM.. Reason: code tags
# 2  
Old 05-10-2012
Code:
awk '{print substr($0,1,10)" "substr($0,11,length($0))}' input.txt
2012-01-10 12:30:55|7323456|65432
2011-02-03 13:11:06|1223|3456

---------- Post updated at 02:28 PM ---------- Previous update was at 02:26 PM ----------

Code:
$ sed 's/\(..........\)\(.*\)/\1 \2/' input.txt
2012-01-10 12:30:55|7323456|65432
2011-02-03 13:11:06|1223|3456

---------- Post updated at 02:29 PM ---------- Previous update was at 02:28 PM ----------

Code:
$ sed 's/\(.\{10\}\)\(.*\)/\1 \2/' input.txt
2012-01-10 12:30:55|7323456|65432
2011-02-03 13:11:06|1223|3456

# 3  
Old 05-10-2012
Thank you so much. All that worked perfect.
# 4  
Old 05-10-2012
One more Smilie

Code:
# sed 's/........../& /' infile

# 5  
Old 05-10-2012
Code:
 
$ perl -lane '$_=~s/^(\d{4}-\d{2}-\d{2})(.*)/$1 $2/;print $_' input.txt
2012-01-10 12:30:55|7323456|65432
2011-02-03 13:11:06|1223|3456

---------- Post updated at 02:44 PM ---------- Previous update was at 02:36 PM ----------

Code:
 
$ perl -lane '$_=~s/^(.{10})(.*)/$1 $2/;print $_' input.txt
2012-01-10 12:30:55|7323456|65432
2011-02-03 13:11:06|1223|3456

# 6  
Old 05-10-2012
Yet one more:
Code:
sed 's/./& /10'

# 7  
Old 05-18-2012
Code:
sed 's/\([0-9]\{2\}:\)/ \1/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert space in a word using sed

Hi all, I have a file that looks like this- ----------------------------- . . ATOM 8 O2' U A 5 135.452 109.687 7.148 1.00 48.99 A16S ATOM 9 C1' U A 5 135.282 111.512 5.641 1.00 48.99 A16S ATOM 10 N1 U A 5 134.647 112.595 ... (2 Replies)
Discussion started by: asmi_g
2 Replies

2. UNIX for Dummies Questions & Answers

sed command to Insert a line before the last four lines of the file

By using sed command, How to insert a new line before the last four lines of the file. Old Line Old Line NEW LINE! Old Line Old Line Old Line Old Line (8 Replies)
Discussion started by: wridler
8 Replies

3. Shell Programming and Scripting

Insert charactera in 1st position of specific lines using vi editor or sed command

Dear all, i am having text file like below surya rama ranga laxman rajesh reddy i want add string (OK) before a text from line 3 to 5 the result will be surya rama OK ranga OK laxman OK rajesh reddy (1 Reply)
Discussion started by: suryanarayana
1 Replies

4. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies

5. Shell Programming and Scripting

help - sed - insert space between string of form XxxAxxBcx, without replacing the pattern

If the string is of the pattern XxxXyzAbc... The expected out put from sed has to be Xxx Xyz Abc ... eg: if the string is QcfEfQfs, then the expected output is Qcf Ef Efs. If i try to substitute the pattern with space then the sed will replace the character or pattern with space,... (1 Reply)
Discussion started by: frozensmilz
1 Replies

6. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

7. Shell Programming and Scripting

Insert space between characters using sed

Input: Youcaneasilydothisbyhighlightingyourcode. Putting space after three characters. You can eas ily dot his byh igh lig hti ngy our cod e. How can i do this using sed? (10 Replies)
Discussion started by: cola
10 Replies

8. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

9. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

10. Shell Programming and Scripting

SED command to change ./ to a space

Hello, i'm trying to remove the ./ from this file using this SED command: sed 's/.///g' all3.lst > all4.lst Does anyone know the correct format for this? For example, i'm trying to convert ./_ABMSTR.TXT.out to: _ABMSTR.TXT.out Thanks... (11 Replies)
Discussion started by: bobk544
11 Replies
Login or Register to Ask a Question