Alternate work out for sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Alternate work out for sed command
# 1  
Old 12-08-2009
Alternate work out for sed command

Iam trying to insert a line after #Cluster in the property file shown below
Code:
#Node=Nodehostname:NodeProfilename
Node=testNode:test_profile
#Cluster=Cluster_Name:nodeName@ClusterMem1,nodeName@ClusterMem2,....
#DC=DCname:DCnodegrp:DCtemp
DC=test_DC:test_NG:test_template

i was using sed command
Code:
sed -e "/^#Cluster=/ a\Cluster=test_node1@test_clus_mem1" /tmp/test.props

to insert and it was working great in Linux and below is the o/p
Code:
#Node=Nodehostname:NodeProfilename
Node=testNode:test_profile
#Cluster=Cluster_Name:nodeName@ClusterMem1,nodeName@ClusterMem2,....
Cluster=test_node1@test_clus_mem1
#DC=DCname:DCnodegrp:DCtemp
DC=test_DC:test_NG:test_template

but when i was trying to use the same code in solaris it fails .
I even have tried using the perl command but was unsuccessful. Below is the perl command that i have used.
Code:
perl -pi -e "/^#Cluster=/ a\Cluster=test_node1@test_clus_mem1" /tmp/test.props

Is there any work around to insert a line using Perl in solaris?

Last edited by pludi; 12-08-2009 at 12:50 PM.. Reason: code tags, please....
# 2  
Old 12-08-2009
You probably need to put the part after the \ on a new line like so:
Code:
sed "/^#Cluster=/ a\
Cluster=test_node1@test_clus_mem1" /tmp/test.props

Alternatively you could use something like this:
Code:
sed "/^#Cluster=/{N;s/\n/&Cluster=test_node1@test_clus_mem1&/}" /tmp/test.props

# 3  
Old 12-08-2009
I have tried entering in a different line but i get the error below .
Code:
sed: command garbled: /^#Cluster=/a        Cluster=test_cluster:test_node@test_cluster_mem1,test_node2@test_cluster_mem

Is there any other way or command that can be used to insert a line in Solaris?
# 4  
Old 12-08-2009
Did you try the second solution I provided?
# 5  
Old 12-08-2009
Code:
nawk '/^#Cluster=/ {$0=$0"\nCluster=test_node1@test_clus_mem1"}1 ' /tmp/test.props

# 6  
Old 12-09-2009
@Scrutinizer
When i tried the second solution and the result was the same
Code:
sed: command garbled: /^#Cluster=/{N;s/\n/&Cluster=test-cluster1:test_node1@test-cluster1-mem1,test_node2@test-cluster1-mem2&/}

@rdcwayx
the nawk command didn't work too. i have got the error below:
Code:
nawk: syntax error at source line 1
 context is
        /^#Cluster=/ >>>  {. <<< /testScript.sh=./testScript.sh\nCluster=stest-cluster1:test_node1@test-cluster1-mem1,test_node2@test-cluster1-mem2}1
nawk: illegal statement at source line 1

# 7  
Old 12-09-2009
Code:
nawk '1; /^#Cluster=/ { print "Cluster=test_node1@test_clus_mem1" }' /tmp/test.props

#Node=Nodehostname:NodeProfilename
Node=testNode:test_profile
#Cluster=Cluster_Name:nodeName@ClusterMem1,nodeName@ClusterMem2,....
Cluster=test_node1@test_clus_mem1
#DC=DCname:DCnodegrp:DCtemp
DC=test_DC:test_NG:test_template

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed command does not work as expected

Why when I use this command do I get "E123"? echo NCE123 | sed -n 's/\(.*\)\(\{1,\}\{1,5\}\)\(.*\)/\2/p' But when I used this command, I get NCE123? echo NCE123 | sed -n 's/\(.*\)\(\{3\}\{1,5\}\)\(.*\)/\2/p' I thought \{1,\} would mean any number of characters and \{1,5\ would mean 1-5... (1 Reply)
Discussion started by: newbie2010
1 Replies

2. Shell Programming and Scripting

Process alternate lines in awk/sed/perl

hi.. i have a fasta file with the following format >sequence1 CCGGTTTTCGATTTGGTTTGACT >sequence2 AAAGTGCCGCCAGGTTTTGAGTGT >sequence3 AGTGCCGCAGAGTTTGTAGTGT Now, i want to read alternate line and add "GGGGGGGGGGG" to end of every sequence Desired output: >sequence1... (4 Replies)
Discussion started by: empyrean
4 Replies

3. Shell Programming and Scripting

Alternate for sed -i in AIX

Experts, At the moment I am working in AIX box where sed -i is not available. My requirement is as below Two files file1 and file2. file1 contains the IP address, its count. file2 contains the Hostname and its corresponding IP address. I would like get the IP address replaced with the apt... (7 Replies)
Discussion started by: sathyaonnuix
7 Replies

4. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfile This code... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

5. Shell Programming and Scripting

sed command works on Fedora/Ubuntu, but doesn't work in Mac

Hi, I have a question. I define a function using sed command: replace() { searchterm=$1 replaceterm=$2 sed -e "s/$searchterm/$replaceterm/ig" $3 > $WORK'tempfile.tmp' mv $WORK'tempfile.tmp' $3 } Then I call replace 'test = 0' 'test = 1' $myfileThis code works well in... (1 Reply)
Discussion started by: Dark2Bright
1 Replies

6. Shell Programming and Scripting

alternate for "grep -vf" command

I have been using grep for removing lines of a particular pattern from a long file in the following way grep -vf Exclude_Lines File1 > File2 But grep seems to have some problems because sometimes it does the job, sometimes it does not....I have seen AWK is more powerful.. Can the same thing... (5 Replies)
Discussion started by: ananyob
5 Replies

7. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

8. UNIX for Dummies Questions & Answers

sed command not work with variables?

I am trying to write a simple script which will take a variable with sed to take a line out of a text and display it #!/bin/sh exec 3<list while read list<&3 do echo $list sed -n '$list p'<list2 done this does not work, yet when I replace the $list variable from the sed command and... (1 Reply)
Discussion started by: MaestroRage
1 Replies

9. UNIX for Dummies Questions & Answers

require alternate command for lsof

Using lsof command i can find out which process-id is associated with the port. lsof -i :51000 . But as part of process i cant have lsof in the server. I am using sun solaris 8 and only kshell. Is there a way to find out which process is using the above port. as of now i am gettn port... (1 Reply)
Discussion started by: logic0
1 Replies

10. Shell Programming and Scripting

Alternate command for cut

Hello, I have a string below DUMMY=1,2,3,4,5,6 I want to extract fields 1-3 and put it as under in a file 1,2,3 I can do this using cut like below echo $DUMMY | cut -d, -f1-3 But I would be processing more than 15000 such entries and I found that "cut" was using more CPU. So anyone... (2 Replies)
Discussion started by: Mohammed
2 Replies
Login or Register to Ask a Question