Inserting a long string (readable in sed)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting a long string (readable in sed)
# 1  
Old 02-06-2013
Inserting a long string (readable in sed)

Hi everyone,

I am trying to insert a single very long string as the first line of a file,
So the following sed commands does what I want;
Code:
sed '1i\"","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"'  file.txt

Think that all the letters contain some more complicated string elements.
This is not very nice and readable in bash script, so I tried to cut the string in multiple lines
just in script file to be able to read and change it easily.

I would like to write the script in such a way
Code:
sed '1i\"","a","b","c","d","e","f","g", \
           "h","i","j","k","l","m","n", \
           "o","p","q","r","s","t","u", \
           "v","w","x","y","z"'  file.txt

but putting \ throws the rest of the string to the next row.

I even tried as the following
Code:
ag="a","b","c","d","e","f","g", 
hn="h","i","j","k","l","m","n",
ou="o","p","q","r","s","t","u",
vz="v","w","x","y","z"
sed '1i\"",$ag$hn$ou$vz' file.txt

this did not work either.

I will appreciate all your help.
thanks.

Last edited by hayreter; 02-06-2013 at 04:51 PM..
# 2  
Old 02-06-2013
Code:
ag="\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\"",
hn="\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\"",
ou="\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\"",
vz="\"v\",\"w\",\"x\",\"y\",\"z\""
sed "1i\"\",$ag$hn$ou$vz" file.txt

This User Gave Thanks to Yoda For This Post:
# 3  
Old 02-06-2013
thanks a lot bipi, you again saved my day Smilie
# 4  
Old 02-07-2013
Try also
Code:
$ echo "a","b","c","d","e","f","g",\
"h","i","j","k","l","m","n",\
"o","p","q","r","s","t","u",\
"v","w","x","y","z" | cat - file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inserting into long delimited string using perl.

Hi, I have a very long pipe delimited string. The length of the string could vary. For example: START|one|two|three|four|five|six|seven START|one|two|three|four|five|six|seven|eight|nine START|one|two|three|four I want to replace in the third occurence of string with another... (9 Replies)
Discussion started by: som.nitk
9 Replies

2. Shell Programming and Scripting

Inserting blank lines after string change

My input data looks like this ... -150 120 8 -150 122 7 -150 124 11 -150 126 8 -150 128 19 -150 130 13 -150 132 26 -150 134 38 -150 136 45 -150 138 62 -150 140 75 -150 142 110 -150 144 139 -150 146 138 -150 148 158 -150 150 173 -150 152 217 (5 Replies)
Discussion started by: chrisjorg
5 Replies

3. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

4. Shell Programming and Scripting

Inserting a string in another sting

Hi Experts, I need to insert a sting into another string at a specified position. Like the below. Regards, Tin-Tin (3 Replies)
Discussion started by: tinufarid
3 Replies

5. Shell Programming and Scripting

Inserting text with SED

Hi guys, I need to insert @test.com after each entry in my .txt file. 1 2 3 4 1@test.com 2@test.com 3@test.com 4@test.com Tried to use cat test.txt |sed 's/$/@test.com/'but it does this instead: 1 @test.com 2 (6 Replies)
Discussion started by: spirm8
6 Replies

6. UNIX for Dummies Questions & Answers

Escaping non-readable characters using grep, sed or awk

I'm trying to parse out DNS logs from dozens of different domain controllers over a large period of time. The logs are rolled up into individual text files by size, which may contain only a portion of a day's activity or several day's worth (depending on amount of activity). I'm splitting them by... (4 Replies)
Discussion started by: seanwpaul
4 Replies

7. Shell Programming and Scripting

inserting a string to a text file

Hello Can somebody please help me with the following script? I'm trying to create a text file with 20 blank lines and then insert a string in line 2 but nothing is printed in the itxtfile. I can create the file with 20 blank lines but when I "tell" it to print something on the second line, it... (4 Replies)
Discussion started by: goude
4 Replies

8. Shell Programming and Scripting

inserting a character between string

i have a file contains like this: i want to create a script that will insert a comma "." after the 10th character so it would be look like this thanks in advance (5 Replies)
Discussion started by: dakid
5 Replies

9. Shell Programming and Scripting

Inserting a String in a file header.

Dear all, I have a file created in the name sample.txt in UNIX with header and footer. How to insert a required string (for example "FILE1") in the header part after the file has been created. What kind of command can i use to do the same. Thanks in advance Hari (3 Replies)
Discussion started by: Hari123
3 Replies

10. Shell Programming and Scripting

inserting a String in the file(s)

Hi, I'm a newbee to Unix shell scripting. I want to write a shell script that inserts a new String(name&value pair) into a file(s) at a particular place.I willl have to write one script which when executed should insert a new variable in all the files in that particular directory. Say for eg:... (4 Replies)
Discussion started by: 2tbee
4 Replies
Login or Register to Ask a Question