LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2019, 12:03 AM   #1
chinna448
LQ Newbie
 
Registered: Jul 2019
Posts: 3

Rep: Reputation: Disabled
Sed script error


I am trying to implement a sed script to a notepad file.

And I am getting below error,

sed: can't find label for jump to 'ak'


not sure what is wrong
 
Old 07-03-2019, 12:05 AM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Pretty hard for us to help without seeing the sed command that’s causing the error...

notepad? On Linux???
 
Old 07-03-2019, 12:16 AM   #3
chinna448
LQ Newbie
 
Registered: Jul 2019
Posts: 3

Original Poster
Rep: Reputation: Disabled
linux
 
Old 07-03-2019, 12:20 AM   #4
chinna448
LQ Newbie
 
Registered: Jul 2019
Posts: 3

Original Poster
Rep: Reputation: Disabled
My script is something like below to replace port in the file template.txt and rename as test.txt. This script is named as test .sh

#!/bin/bash




filename="test.txt
port="80"

cp template.txt $filename

sed -i.bak "s/port/$port/g" $filename




I am implementing script as below and getting error as below,

#test.sh
sed: can't find label for jump to 'ak'
sed: can't find label for jump to 'ak'
sed: can't find label for jump to 'ak'
sed: can't find label for jump to 'ak'
sed: can't find label for jump to 'ak'
 
Old 07-03-2019, 01:33 AM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Show us the source file...template.txt?

We can’t help without complete information.
 
Old 07-03-2019, 02:58 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you might want to use shellcheck to check your script.
Without exact information hard to say anything.
 
Old 07-03-2019, 06:37 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by chinna448 View Post
My script is something like below to replace port in the file template.txt and rename as test.txt. This script is named as test .sh
Do not name files or scripts with the name test. It is a built-in bash command. Credit to rknichols for that knowledge, because I made the exact same mistake just a short while ago.
Quote:
Originally Posted by chinna448 View Post
[/code]#!/bin/bash


[/code]
What are these garbage characters at the end of every code line? They should not be there.
 
Old 07-03-2019, 11:44 AM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by rtmistler View Post
What are these garbage characters at the end of every code line? They should not be there.
I'm not seeing that, but given the OP is talking about a "notepad" file, I'd suspect DOS line ends, which would, of course, mess up things on Linux.
 
Old 07-03-2019, 09:16 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Here are some points to help us:

1. Please use [code][/code] tags around your code

2. As you have mentioned "notepad", please advise if any files used (script or files being read) were written under a Windows environment?

3. As advised by pan64, please use shellcheck on your script to find any basic error (such as the missing quotes from filename="test.txt)

Please update question once above have been performed
 
Old 07-04-2019, 04:36 AM   #10
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,791

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Code:
sed -i.bak "s/port/$port/g" $filename

is correct.
But I guess you did
Code:
sed -i bak "s/port/$port/g" $filename

and that's something totally different:
Now bak becomes the sed code, causing the said error message.
 
Old 07-04-2019, 08:41 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
quoting is wrong.
test file says,
Code:
pea green soup
sed says,
Code:
$ var=red
$ sed  's|green|'$var'|g' testfile
pea red soup
to get sed to actually change the file itself, rather than show you the results on the cli, add your -i
Code:
sed -i 's|green|'$var'|g' testfile
Single quotes all around. That is the way I've always done it.

For the others, he said notepad file. being the txt to denote a notepad file.

OP:
If you are looking for the word(s) 'port=??' and want to replace it with 'port=80'.
Code:
#!/bin/bash

filename="testfile"
Template="template.txt"
port="port=80"

#test for files presents before issuing commands on it. 
[[ -f "$Template" ]] &&
     { cp "$Template" "$filename" ;
      sed -i 's|port.*|'$port'|g' "$filename" ;
       cat "$filename" ; }
#cat can be used for testing purposes to show results.

    read -p "Do you want to make this your file? " ans
	
    [[ "${ans,,}" = 'y' ]] && 
        { echo "Otay.. changing it to template file" ; 
	 mv -v $filename $Template ;
	 echo " done deal..." ; } ||
     { echo "OTay, not doing that..." ; }

Last edited by BW-userx; 07-04-2019 at 09:11 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sed script within bash script produces unexpecte EOF error Kgeil Linux - Newbie 8 05-16-2019 12:41 AM
Sed substitution gives error "sed: command garbled" gsai0205 Linux - Newbie 3 09-13-2013 09:01 AM
script.pl with sed shell calls: sh error syntax error near unexpected token `(' MMaddoxx Programming 7 11-24-2011 08:00 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration