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
Locale::Codes::LangExt(3)				User Contributed Perl Documentation				 Locale::Codes::LangExt(3)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-02-27 Locale::Codes::LangExt(3)
All times are GMT -4. The time now is 05:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy