Sponsored Content
Top Forums Shell Programming and Scripting sed command throwing error while deleting a line from a file Post 302902817 by vivek d r on Thursday 22nd of May 2014 11:29:31 AM
Old 05-22-2014
sed command throwing error while deleting a line from a file

Hi all,


I ahve a program which has to delete a line in a file... if i run the sed command through shell prompt it works fine. But if run it using code its throwing error. May i know where i am doing wrong.



the file has 3 lines
Code:
[root@ ~]# cat /root/.ssh/known_hosts
|1|MXOU9X7fgx6AHKiY334LC42jZ1Q=|cWBsRbmCKgYzDotT1TuVS1iyc3s= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzwqooVvj4pkERPlaxfCqbhOeuha3bbv3/YLLy6+drGn8W2mV/sS2vrOfHnYfU3xGdWNt6GFoA7PC5dEdU/MWlkMcxq4y7ceBVVojl9Q1qJntHpEvzW6oKNMg+Usx4BiuAOBqpCgcdequBCBzsvFdO7boJXckwanEVLAkI91Nlo/8bafQYCiOcxIx7D15UPFvVEUd+H7PSs8YC7FySymXTOuq45ppQfHV3ztlF9LWUasbTDKdUhmysV0dos49GzhMUkyrbph+NC+J/jWAMXAtHTiIbi9Sy4tVXpcM8Aq+8isDMpBKtIjESsF7Lei4xD9GKQUdz7sp4MgK3EjL0/hJww==
|1|j5o3eNW9A4j5UKZ8xUCQqCVlym4=|paupRZ08Js918aoLZO1mwQRgUYE= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt9rMbOvoPnaL0TJdENoYA1ZOrALwXTEbjyi67cxNOYAQzdjbNgm3bUXkAjumhgjGLwSz04PbjXFv+W+bTffh2EDFuQSW6tEiG1ITTsckOymG6My0A5zSLPsaIAGIWgo9F+mw8x6URAY6yBT+ja187CpjhVoUMnJrE5ght+3PZaRJcFdSWlT3izj3++4khpS+Q4cxNogCuEslGxN5uAxBFbQLxkp3qFEJGCAOl1zrU5gcmTLeIO1Q3+fBEX3F1u3y0/+/vcZ55ZOSkHUvxOVUZ0u3RdWId0sAL5yNrexj8jrsgziJnjWrHhNOjtH0Ou33VXOxyBTCvWmtxex2plTgyw==
|1|RcXETg1pFCqRpgvAB9tVWoL0pl8=|uW/xYTXcf+O22U8Xam4dT35C0gE= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt9rMbOvoPnaL0TJdENoYA1ZOrALwXTEbjyi67cxNOYAQzdjbNgm3bUXkAjumhgjGLwSz04PbjXFv+W+bTffh2EDFuQSW6tEiG1ITTsckOymG6My0A5zSLPsaIAGIWgo9F+mw8x6URAY6yBT+ja187CpjhVoUMnJrE5ght+3PZaRJcFdSWlT3izj3++4khpS+Q4cxNogCuEslGxN5uAxBFbQLxkp3qFEJGCAOl1zrU5gcmTLeIO1Q3+fBEX3F1u3y0/+/vcZ55ZOSkHUvxOVUZ0u3RdWId0sAL5yNrexj8jrsgziJnjWrHhNOjtH0Ou33VXOxyBTCvWmtxex2plTgyw==
[root@ ~]#

The error thrown is as below...
Code:
here 1 : lineno: 1
'ed: -e expression #1, char 2: unknown command: `
here 2
'ed: -e expression #1, char 2: unknown command: `

below is the part of the code where its going wrong.
Code:
echo "here 1 : lineno: $lineno"
sed -i "${lineno}d" /root/.ssh/known_hosts
echo "here 2"
sed -i ''$lineno'd' '/root/.ssh/known_hosts'


can anyone give me a quick fix for this. any help is deeply appreciated. thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Deleting all content in a file from command line

Hey guys, I'd like to delete all text within a text file without actually deleting the file. Is there a vi command I can do from my prompt without actually going into the file and doing a %d i think it is... to remove all the text inside? I want to add this to a cron job to erase all the data... (2 Replies)
Discussion started by: kingdbag
2 Replies

2. UNIX for Dummies Questions & Answers

Remote login/copy command throwing an error

Hi We had 3 server -hp112and hp146 here hp112 is production server and hp146 is staging server used for load. when i am trying to run follwing command rcp abc hp112:/dnbusr1/gbid/gbid02 it's trowing an error :- remshd: Login incorrect. But same command is working wise versa - rcp abc... (1 Reply)
Discussion started by: ashish_panpalia
1 Replies

3. Shell Programming and Scripting

Deleting a line from a file with sed and awk?

cat file.txt fvnuiehuewf ruevhxncvkjrh zxjvurhfuwe jkhvBEGINvfnvf ijrgioe Trying to delete a line that has the pattern "BEGIN" cat sedtest filename=file.txt pattern=BEGIN sed "/^$pattern/d" "$filename" (9 Replies)
Discussion started by: cola
9 Replies

4. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

5. UNIX for Dummies Questions & Answers

Mailx command in unix shell script, its throwing below error

How to use Mailx command in unix shell script, its throwing below error #!/bin/ksh let x=3 If ; then mailx -s “ $x is greater than 2” example@gmail.com << EOF This is the message body EOF fi its throwing error as syntax error at EOF... (10 Replies)
Discussion started by: only4satish
10 Replies

6. UNIX for Dummies Questions & Answers

Deleting "user input line number" from a file using sed

Hi I want to delete a line from a txt file for which the line number is user input. Say when user selects 19, the 19th line would be deleted from the file. Can anyone please provide me with a sed one liner for the same... I tried sed -i. The interaction would be like this Enter the line to... (1 Reply)
Discussion started by: sudeep.id
1 Replies

7. Shell Programming and Scripting

for loop with internal unix command in statement throwing error

Hi I've gotten a plugin script that won't run. I keeps throwing an error at the following line. for BARCODE_LINE in `cat ${TSP_FILEPATH_BARCODE_TXT} | grep "^barcode"` do #something done The error reads ... (3 Replies)
Discussion started by: jdilts
3 Replies

8. Shell Programming and Scripting

Deleting "user input line number" from a file using sed

Hi I want to delete a line from a txt file for which the line number is user input. Say when user selects 19, the 19th line would be deleted from the file. Can anyone please provide me with a sed one liner for the same... I tried sed -i. The interaction would be like this Enter the line... (4 Replies)
Discussion started by: sudeep.id
4 Replies

9. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

10. Shell Programming and Scripting

sed command within script wrongly deleting the last line

Hi, I have a shell script which has a for loop that scans list of files and do find and replace few variables using sed command. While doing this, it deletes the last line of all input file which is something wrong. how to fix this. please suggest. When i add an empty line in all my input file,... (5 Replies)
Discussion started by: rbalaj16
5 Replies
SSH-KEYSIGN(8)						    BSD System Manager's Manual 					    SSH-KEYSIGN(8)

NAME
ssh-keysign -- ssh helper program for host-based authentication SYNOPSIS
ssh-keysign DESCRIPTION
ssh-keysign is used by ssh(1) to access the local host keys and generate the digital signature required during host-based authentication with SSH protocol version 2. ssh-keysign is disabled by default and can only be enabled in the global client configuration file /etc/ssh/ssh_config by setting EnableSSHKeysign to ``yes''. ssh-keysign is not intended to be invoked by the user, but from ssh(1). See ssh(1) and sshd(8) for more information about host-based authen- tication. FILES
/etc/ssh/ssh_config Controls whether ssh-keysign is enabled. /etc/ssh/ssh_host_dsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_rsa_key These files contain the private parts of the host keys used to generate the digital signature. They should be owned by root, read- able only by root, and not accessible to others. Since they are readable only by root, ssh-keysign must be set-uid root if host- based authentication is used. /etc/ssh/ssh_host_dsa_key-cert.pub /etc/ssh/ssh_host_ecdsa_key-cert.pub /etc/ssh/ssh_host_rsa_key-cert.pub If these files exist they are assumed to contain public certificate information corresponding with the private keys above. SEE ALSO
ssh(1), ssh-keygen(1), ssh_config(5), sshd(8) HISTORY
ssh-keysign first appeared in OpenBSD 3.2. AUTHORS
Markus Friedl <markus@openbsd.org> BSD
August 31, 2010 BSD
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy