Shell quoting problem while editing a remote file using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell quoting problem while editing a remote file using sed
# 1  
Old 11-07-2012
Shell quoting problem while editing a remote file using sed

value of i = solarisbox

Code:
ssh $i "cat /etc/hosts | sed "s/$i\.local\.//" | sed "s/$i\./$i/" | sed "s/$i/$i.sol.com/" > /usr/users/chidori/edit_hosts"

While running the above one liner its i am not able to make the changes and write it to the file /usr/users/chidori/edit_hosts . I know there is a quoting problem. Please help in fixing it.

Input:
Code:
# cat /etc/hosts
#
# Internet host table
#
::1     localhost
127.0.0.1       localhost
1.1.1.1  solarisbox solarisbox.local. solarisbox.  loghost loghost2

Desired output :
Code:
#
# Internet host table
#
::1     localhost
127.0.0.1       localhost
1.1.1.1  solarisbox.sol.com  solarisbox  loghost loghost2

# 2  
Old 11-07-2012
Try (I haven't changed/optimized your substitutions, just used a single sed to do the required job):
Code:
ssh "$i" "sed 's/$i\.local\.//
s/$i\./$i/
s/$i/$i.sol.com/
' /etc/hosts > /usr/users/chidori/edit_hosts"

# 3  
Old 11-07-2012
Thanks it works.. but is it possible to achieve it in a single line ?

Last edited by chidori; 11-07-2012 at 10:25 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Editing a file on remote server using shell script locally

Hi Scott, My previous post was not for any school or college projects. I am currently working with a IT company (Cannot provide more details than this). I am trying to implement the below script in my day-to-day work, Apologies for the confusion in previous post :). My question remains same... (4 Replies)
Discussion started by: Nishant Ladiwal
4 Replies

2. Shell Programming and Scripting

Editing a file on remote server using shell script locally

Hi All, I have below requirements for my project: 1. Building a shell script which connects to a remote server 2. running script on local machine as user 'A' 3. connecting to server using user 'B' with password 4. login with a powerbroker role 'P' (asks for same password as 'B') on that... (1 Reply)
Discussion started by: Nishant Ladiwal
1 Replies

3. Shell Programming and Scripting

editing file with awk cut and sed

HI All, I am new to unix. I have a file would like to do some editing by using awk, cut and sed. Could anyone help? This file contain 100 lines. There are one line for example: 2,"102343454",5060,"579668","579668","579668","SIP",,,"825922","035885221283026",1,268,"00:59:00.782 APR 17... (2 Replies)
Discussion started by: mimilaw
2 Replies

4. Shell Programming and Scripting

Problem with searching and then editing a file through shell.

Hi, I have searched through this forum as there are many similar entries but could'nt get one of them to work, either that or they were just different to what I needed. Basically I have a file, recordsDatabase. In this file are a few different fields. There is a unique identifier eg 001... (5 Replies)
Discussion started by: U_C_Dispatj
5 Replies

5. Shell Programming and Scripting

problem in using sed command in editing a file

Hi all, I have a conf file, i want to update some entries in that conf file. Below is the code for that using a temporary file. sed '/workgroup=/ c\workgroup=Workgroup' /usr/local/netx.conf > /usr/local/netx.conf.tmp mv -f /usr/local/netx.conf.tmp /usr/local/netx.conf Sample contents of... (9 Replies)
Discussion started by: ranj14r
9 Replies

6. Shell Programming and Scripting

awk quoting problem

I think this has to do with the quoting, I just feel I've been looking at it too long. Thanks ~T prompt> cat my.awk BEGIN{"date +%d%b%Y.%H%M%S" | getline sDate} { if (substr($0,151,1) ~ /6/ ) print >> sDate".NEW_ORDER.dat" # print >> sDate # note this works to output the contents to sDate,... (2 Replies)
Discussion started by: tcstuff
2 Replies

7. Shell Programming and Scripting

SED - editing file names (End of line problem?)

For lists in sed, to say what to replace, is this correct: I am hoping that this would recognise that either a "." is present, or that the substitution happens at the end of the line. For files with extensions , my script works perfectly. My problem is, files without extentions, i.e. . ... (1 Reply)
Discussion started by: busillis
1 Replies

8. Shell Programming and Scripting

Quoting problem with `date`

I'm trying to take the command `date` giving me: Fri Feb 22 09:23:52 EST 2008 and using some command take out the rest of the string leaving me with "Fri Feb 22" any help appreciated hopefully thanks in advance (3 Replies)
Discussion started by: cleansing_flame
3 Replies

9. Shell Programming and Scripting

Editing File using awk/sed

Hello Awk Gurus, Can anyone of you help me with the below problem. I have got a file having data in below format pmFaultyTransportBlocks ----------------------- 9842993 pmFrmNoOfDiscRachFrames ----------------------- NULL pmNoRecRandomAccSuccess -----------------------... (4 Replies)
Discussion started by: Mohammed
4 Replies

10. UNIX for Dummies Questions & Answers

problem editing big file in vi

I have a big file, which vi opens it with message not sufficient space with file system. I am not adding any data in the file but changing some values within. To make these changes effective, it asks for forced write (w!), even after doing this, I see this particular record, change is not... (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question