add a string to a file without line break


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers add a string to a file without line break
# 8  
Old 10-26-2012
Change
Code:
ssh ${_user}@${_ip} "sudo /bin/sed -i '$s/$/ elevator=noop/' /home/wadhwaso/test "

to
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed -i "\$s/\$/ elevator=noop/" /home/wadhwaso/test'

.
Single-quotes lose their ability of quoting when they are enclosed within double-quotes. So, your shell will still look within that string and expand $s to a null string even before ssh is executed.

Last edited by elixir_sinari; 10-26-2012 at 03:52 AM..
# 9  
Old 10-26-2012
Quote:
Originally Posted by elixir_sinari
Change
Code:
ssh ${_user}@${_ip} "sudo /bin/sed -i '$s/$/ elevator=noop/' /home/wadhwaso/test "

to
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed -i "\$s/\$/ elevator=noop/" /home/wadhwaso/test'

.
Single-quotes lose their ability of quoting when they are enclosed within double-quotes. So, your shell will still look within that string and expand $s to a null string even before ssh is executed.
That worked, Thanks a lot Elixir ..

can you tell me one thing more, I want to add that string "elevator=noop" in /etc/grub.conf at the end of all the lines starting with "kernel", so i did:
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed -i "/kernel/ \$s/\$/ elevator=noop/" /etc/grub.conf'

but its not working, it gave me following error:

HTML Code:
sed: -e expression #1, char 10: unknown command: `$'
# 10  
Old 10-26-2012
Quote:
Originally Posted by stunn3r
I want to add that string "elevator=noop" in /etc/grub.conf at the end of all the lines starting with "kernel",
Try

Code:
ssh ${_user}@${_ip} 'sudo /bin/sed  "s/kernel.*/& elevator=noop/" /etc/grub.conf'

This User Gave Thanks to pamu For This Post:
# 11  
Old 10-26-2012
Quote:
Originally Posted by pamu
Try

Code:
ssh ${_user}@${_ip} 'sudo /bin/sed  "s/kernel.*/& elevator=noop/" /etc/grub.conf'

Thanks, that worked Smilie .. just added "-i" .. Smilie

just one thing, it adds parameter "elevator=noop" to those lines too which are commented. Is it possible to add this parameter to only those lines which START with 'kernel', if a line start with "#" or something else, it should ignore that line ..

Last edited by stunn3r; 10-26-2012 at 05:13 AM..
# 12  
Old 10-26-2012
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed  "s/^kernel.*/& elevator=noop/" /etc/grub.conf

This User Gave Thanks to elixir_sinari For This Post:
# 13  
Old 10-26-2012
Quote:
Originally Posted by elixir_sinari
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed  "s/^kernel.*/& elevator=noop/" /etc/grub.conf

worked perfectly ..

but there are spaces before kernel .. its like " kernel ......" , and these spaces wont be constant for all the servers. any way to ignore these spaces ??
# 14  
Old 10-26-2012
Code:
ssh ${_user}@${_ip} 'sudo /bin/sed  "s/^[ <tab>]*kernel.*/& elevator=noop/" /etc/grub.conf

where <tab> should be replaced by pressing the Tab key.
This User Gave Thanks to elixir_sinari For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

2. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

4. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

5. Shell Programming and Scripting

Add Some String on each line of file

HI Guys, I am new user its my first post. I have one file in DIR XYZ. File name is ABCDEF.log Now i want to add that file in each line of file. I have data in file ABCDEF.log TestKLFH TEstLKHU HESTLJHG Now i want to update the file with below data ABCDEFG.log:TestKLFH... (5 Replies)
Discussion started by: asavaliya
5 Replies

6. Shell Programming and Scripting

break the string and print it in a new line after a specific word

Hi Gurus I am new to this forum.. I am using HP Unix OS. I have one single string in input file as shown below Abc123 | cde | fgh | ghik| lmno | Abc456 |one |two |three | four | Abc789 | five | Six | seven | eight | Abc098 | ........ I want to achive the result in a output file as shown... (3 Replies)
Discussion started by: kannansr621
3 Replies

7. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

8. Shell Programming and Scripting

line break if string exceeds 100chars

I am required to develop a script to look for specific strings in the /var/adm/messages file on our Solaris10 host. When an entry is found in the file then I need that line to be piped to a log file. I have a script with the criteria i just need help with the manipulation of the text string. 1.... (6 Replies)
Discussion started by: s1ckle
6 Replies

9. Shell Programming and Scripting

Trim whitespace and add line break

All, I'm a newbie at shell scripting and regular expressions and I just need to take a file that's arranged like the one below, remove all leading and trailing whitespace and add a line break after each word. I've been able to remove a few spaces using various awk, sed and Perl scripts, but... (7 Replies)
Discussion started by: moose1
7 Replies

10. Shell Programming and Scripting

how to insert line break + string in vi (search & replace )

Hello all i have big test file that has allot of structure text something like this : <foo1 *.html> <blah action> somthing 1 somthing 2 </blah> </foo1 > now i will like to insert 2 more lines of text below the <blah action> so it will be like : <foo1... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question