sed error in UNIX but not Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed error in UNIX but not Linux
# 1  
Old 03-07-2014
sed error in UNIX but not Linux

I was using the following code successfully on a linux system.
Code:
while read pattern; do
  grep -q $pattern en.pep
  if [ $? -ne 0 ]; then continue; fi
  line_number=`grep -m 1 -n $pattern en.pep | cut -f 1 -d :`
  echo ">$pattern"
  sed -n "$line_number { n; p; q}" en.pep
done < file1 > en_peps

But when I run it on unix I get the following error repeated many times with different line (?) numbers. Needless to say this error is not giving me much of a clue (I'm not much of a programmer), and all forum posts I've found were resolved in specific ways that don't apply to my situation.
Code:
sed: 1: "3163 { n; p; q}": extra characters at the end of q command

If someone could shed some light for me I'd appreciate it!
# 2  
Old 03-07-2014
I think you're missing a semi-colon. Try this:
Code:
sed -n "$line_number { n; p; q;}" en.pep

This User Gave Thanks to Perderabo For This Post:
# 3  
Old 03-07-2014
Many Unix sed have bugs with semicolon - newline works better
Code:
sed -n "$line_number {
n
p
q
}
" en.pep

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 03-08-2014
Thanks, both of these solutions worked.
# 5  
Old 03-08-2014
Quote:
Originally Posted by MadeInGermany
Many Unix sed have bugs with semicolon - newline works better [..]
Those are not a bugs:
Quote:
Historically, the sed ! and } editing commands did not permit multiple commands on a single line using a <semicolon> as a command delimiter. Implementations are permitted, but not required, to support this extension.
sed: rationale

Anyway, the OP's sed apparently does support the semicolon (as most seds do nowadays), but since } is a command, there should be a semicolon in front of it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed with regexp in Linux

OFF 00280456 - 2014|1|2020_STATUS|GROUP_NAME|SUBGROUP_NAME|CLASS_NAME|GROUP_ID|SUBGROUP_ID I have above header in file. I need to replace 2020_STATUS with STATUS. 2020_STATUS is not always same but the column name will have STATUS all of the time. For instance column name might be 2019_STATUS... (1 Reply)
Discussion started by: jmadhams
1 Replies

2. What is on Your Mind?

YouTube: Forum Moderation @UNIX.com | The UNIX and Linux Forums

Forum Moderation @UNIX.com | The UNIX and Linux Forums https://youtu.be/WGwgibE4Rq0 Also note: In the video I mentioned removing legacy menu items in the ModCP which are unused. I have already "CSS'ed out" the unused menu items: ... (0 Replies)
Discussion started by: Neo
0 Replies

3. Post Here to Contact Site Administrators and Moderators

VIP Membership - The UNIX and Linux Forums - Get Your UNIX.COM Email Address Here

We work hard to make The UNIX and Linux Forums one of the best UNIX and Linux knowledge sources on the net. The site is certainly one of the top UNIX and Linux Q&A sites on the web. In order to provide certain members the best quality account services, you can now get some great extra features by... (2 Replies)
Discussion started by: Neo
2 Replies

4. UNIX for Beginners Questions & Answers

Simple sed command not working; could be a Mac/Linux vs. PC/Linux issue

Hello, I am on a Mac and trying to clean up some monthly files with a very simple SED: sed '3,10d;/<ACROSS>/,$d' input.txt > output.txt (from the input, delete lines 3 - 10; then delete from the line containing <ACROSS> to the end of the file) then output to output.txt Even when I try... (2 Replies)
Discussion started by: verbatim
2 Replies

5. Fedora

Which is the better platform to learn UNIX/Linux (Kali Linux Vs. Red Hat or other)?

I just started a new semester and I started my UNIX class yesterday. I've already decided to use python along with my learning process but what I really want to use with it is Kali as my UNIX/Linux platform to learn off of since I already wanted to learn Cyber Sec. anyways. I just wanted to know if... (12 Replies)
Discussion started by: ApacheOmega
12 Replies

6. 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

7. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

8. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

9. Shell Programming and Scripting

sed error : Syntax error: redirection unexpected

My script is throwing the error 'Syntax error: redirection unexpected' My line of code.. cat nsstatustest.html | sed s/<tr><td align="left">/<tr><td align="left" bgcolor="#000000"><font color="white">/ > ztmp.Ps23zp2s.2-Fpps3-wmmm0dss3 HTML tags are getting in the way but they're needed to... (3 Replies)
Discussion started by: phpfreak
3 Replies

10. Answers to Frequently Asked Questions

What is unix and is linux a unix system

Unix is the name of an operating system. And unix is a registered trademark. This is what makes things murky. One of my favorite books is The Design and Implementation of the 4.3BSD UNIX Operating System. That book is out of print, but a newer book is available: The Design and Implementation... (0 Replies)
Discussion started by: Perderabo
0 Replies
Login or Register to Ask a Question