Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Using sed to insert at position x and then every interval y for each line Post 302924258 by gusbrown on Friday 7th of November 2014 10:34:11 AM
Old 11-07-2014
Using sed to insert at position x and then every interval y for each line

Thanks to help from Don Cragun in post 302924174, I'm off and getting into trouble on my own (finally) with sed.

Here is my goal - insert
Code:
\\r\n

at the 60th character on each line and then every 76th character thereafter:

Input:
Code:
6F,00,72,00,20,00,73,00,69,00,74,00,20,00,61,00,6D,00,65,00,74,00,2C,00,20,00,63,00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,00,72,00,2E,00,22,00,00,00;
22,00,54,00,68,00,65,00,20,00,71,00,75,00,69,00,63,00,6B,00,20,00,62,00,72,00,6F,00,77,00,6E,00,20,00,66,00,6F,00,78,00,5C,00,20,00,63,00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,00,72,00,2E,00,22,00,00,00;

Output:
Code:
6F,00,72,00,20,00,73,00,69,00,74,00,20,00,61,00,6D,00,65,00,\
74,00,2C,00,20,00,63,00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,\
00,72,00,2E,00,22,00,00,00;
22,00,54,00,68,00,65,00,20,00,71,00,75,00,69,00,63,00,6B,00,\
20,00,62,00,72,00,6F,00,77,00,6E,00,20,00,66,00,6F,00,78,00,5C,00,20,00,63,\
00,6F,00,6E,00,73,00,65,00,63,00,74,00,65,00,74,00,75,00,72,00,2E,00,22,00,\
00,00;

So I tried:
Code:
sed 's/./&\\\r\n/60 s/./&\\\r\n/76' input

but get a syntax error for char 16 being an unknown option to 's'.

This is puzzling to me as I'm able to successfully insert each 60 characters of every line with:
Code:
sed 's/./&\\\r\n/60' input

Shouldn't latter throw the same error?

Kind regads,

gus
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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 Replies)
Discussion started by: tangentviper
2 Replies

2. Shell Programming and Scripting

insert server name in position 1 on each line

Hello, It has been a long time since I have written unix code and I need to insert a variable into the first position of each line in a file. Below is an example of the script and the desired output file Here is my short script server="$(hostname)" df -kg | awk '{print $1, $2, $3, $4,... (3 Replies)
Discussion started by: rlc198842
3 Replies

3. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

4. 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

5. 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

6. 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

7. Shell Programming and Scripting

Insert carriage return on the 10th char position of each line

Hi experts, Need your help on how to insert carriage return after the 10th char position of each line in a file and then add two blank spaces after the carriage return. Example: >cat test.txt testingline dummystring samplesample teststringline Expected output should be.. ... (2 Replies)
Discussion started by: brichigo
2 Replies

8. 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

9. 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

10. 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
fixnt(1)							      Debian								  fixnt(1)

NAME
fixnt - Filter for the Windows NT postscript printer driver. SYNOPSIS
fixnt < BADFILE.ps > GOODFILE.ps DESCRIPTION
The Windows NT postscript driver has a tendency to make broken postscript files, that are incompatible with psutils. fixnt is a filter that fixes these problems, allowing the use of psnup(1). The filter takes the broken postscript file on stdin, and outputs a fixed postscript file on stdout. It has no other form for invocation and takes no options on the command-line. OPTIONS
fixnt takes no options. BUGS
fixnt does not check for NTPSOct94. For a workaround, use a sed(1) command to replace 'NTPSOct94' with 'NTPSOct95', like so: sed 's/NTPSOct94/NTPSOct95/g' This is particularly important for Windows NT 3.5 users. AUTHOR
fixnt was written by Holger Bauer <Holger.Bauer@topmail.de>, Michael Rath <rath@itsm.uni-stuttgart.de>, and Akim Demaille <demaille@inf.enst.fr>. REPORTING BUGS
Report bugs to the Authors, but avoid sending large postscript files. Patches are always welcome; send to <bauer@itsm.uni-stuttgart.de>. SEE ALSO
psnup(1), sed(1) a2ps February 2003 fixnt(1)
All times are GMT -4. The time now is 07:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy