sed - how to insert chars into a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - how to insert chars into a line
# 1  
Old 01-29-2009
sed - how to insert chars into a line

Hi I'm new to sed, and need to add characters into a specific location of a file, the fileds are tab seperated.

text <tab> <tab> text <tab> text EOL

I need to add more characters to the line to look like this:

text <tab> <tab> newtext <tab> text <tab> text EOL

Any ideas?
# 2  
Old 01-29-2009
Code:
root@isau02:/data/tmp/testfeld> od -c infile
0000000   t   e   x   t  \t  \t   t   e   x   t  \t   t   e   x   t  \n
0000020
root@isau02:/data/tmp/testfeld> sed 's/^text\t\t/&newtext\t/' infile
text            newtext text    text
root@isau02:/data/tmp/testfeld> sed 's/^text\t\t/&newtext\t/' infile > outfile
root@isau02:/data/tmp/testfeld> od -c outfile
0000000   t   e   x   t  \t  \t   n   e   w   t   e   x   t  \t   t   e
0000020   x   t  \t   t   e   x   t  \n
0000030

# 3  
Old 02-01-2009
Many Thanks for your reply, I found out about "tr" and translated the file tabs to ":" and once my edits were completed, used "tr" to put them back. Its Solaris 9 and sed doesnt like \t, but tr does.

All the best.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to find and append or insert on SAME line

Hi, $ cat f1 My name is Bruce and my surname is I want to use SED to find “Bruce” and then append “ Lee” to the end of the line in which “Bruce” is found Then a more tricky one…. I want to INSERT ….a string… in to a line in which I find sometihng. So example $ cat f2 My name is... (9 Replies)
Discussion started by: Imre
9 Replies

2. Solaris

sed insert into line 1 via script

Hi I am trying to run a sed command within a script..unfortunately it wasn't written on Solaris so doesn't work. Can anyone help with the correct coding please? It is: sed -i '1i ROWID;ORDER_ID;JOB_NAME;ORDER_TABLE' ${OUTFILE} (4 Replies)
Discussion started by: Grueben
4 Replies

3. UNIX for Dummies Questions & Answers

Grep or sed to search, replace/insert chars!

HI All Im trying to come up with an approach to finding a string, using a portion of that string to insert it on lines starting with the value "GOTO" appending to end of line after removing PT's ( See example below! ) EXAMPLE: 1. I would like to search for the line that starts with "TLAXIS/"... (7 Replies)
Discussion started by: graymj
7 Replies

4. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

5. Shell Programming and Scripting

Insert @Line # - SED (non-GNU)

Just posted on another fellow's question using ed, but I wanted to know about doing it with sed on Unix. For example - I have a file of an unknown length, but I want to add a line after the shell declaration (Line 2). If possible, I'd like the example to be able to just substitute in a number and... (2 Replies)
Discussion started by: Vryali
2 Replies

6. Shell Programming and Scripting

AWK/SED: handle max chars in a line

Hi all, I hope you guys can help me. I prefer SED/AWK solutions if possible. For my shame it didn't work for me :o ISSUE: :wall: 1\3 1/$4\@7\ 1234567890123456789\ 1234567890123456789,\ 1234567890123456789\ 123456789012 12345 1234567890123456789\ 1234567890123456789,\ 1234... (5 Replies)
Discussion started by: unknown7
5 Replies

7. AIX

insert a line with variables using sed

Hi, I have to insert a line having variables using sed. But the variables are not getting substituted within sed. Ex: n=2 sed $n' i\ hi' file This works. But the below code does not work. n=2 line=hello sed $n' i\ $line' file The above code inserts '$line' in the 2nd line of the... (9 Replies)
Discussion started by: sugan
9 Replies

8. Shell Programming and Scripting

sed insert text at particular line

I know that sed -n '12p' file will print line 12 but how might I insert text to a specified line? thanks (2 Replies)
Discussion started by: action_owl
2 Replies

9. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

10. Shell Programming and Scripting

insert new line at found chars

Hey gang, I have: XXZZXXZZXX 123 asdaffggh dfghyrgr ertyhdhh XXZZXXZZXX 234 sdg XXZZXXZZXX 456 gfg fggfd That is all on one line. Very simply put I want to do is something like: sed s'/XXZZXXZZXX /\n/g' or tr 'XXZZXXZZXX ' '/n' I have tried various things but can never get the desired... (6 Replies)
Discussion started by: crowman
6 Replies
Login or Register to Ask a Question