Sponsored Content
Full Discussion: What's wrong my sed?
Top Forums Shell Programming and Scripting What's wrong my sed? Post 302668029 by alister on Sunday 8th of July 2012 12:02:46 PM
Old 07-08-2012
Quote:
Originally Posted by yanglei_fage
Code:
$ cat ./xx.sh 
#!/bin/bash
while read line
do
    sed -n '/${line}/p' ./file2
done < ./file1

You did not show the desired output for the sample data, so I'm assuming that your goal is to print out each line in file2 that contains a line in file1 as a substring.

Code:
grep -Ff file1 file2

Regards,
Alister

---------- Post updated at 12:02 PM ---------- Previous update was at 11:58 AM ----------

Quote:
Originally Posted by yanglei_fage
"The sed command will not work because of the / delimiter"
if I change the sed to " sed -i '%${line}%d' file2" it still get error
sed: -e expression #1, char 1: unknown command: `%'
To use a different delimiter for an address, the opening delimiter must be backslash-escaped (this is not necessary when using a different delimiter to delimit the components of a substitute, s, command).

However, any sed solution will treat literal text as a regular expression. That is a very poor approach. Each . in file1 will match any character at all. Each * will allow the preceding character to occur an arbitrary number of times, or to not occur at all. And so it goes with all regular expression metacharacters.

Regards,
Alister

Last edited by alister; 07-08-2012 at 01:22 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

am i wrong?

knew nothing about unix - linux untill a week ago when i started out to learn the basics. I think i'm aproaching unix wrong, i'm trying to compare unix with dos, searching similar commands. Did some great things for dumbass newbie like writing scripts to mount cdrom and floppy, that's the... (4 Replies)
Discussion started by: termiEEE
4 Replies

2. Shell Programming and Scripting

What's wrong with this sed command? delete & append

I want to write a sed command that does the following work: file: <a>asdfasdf<\s> <line>hello</line> <b>adf<\c> <b>tttttttt<\c> output: name=hello sed -e 's/^*//' -n -e '/<line>/s/<*>//gp;' -e 's/^/name="/g' file but I can not append "=" after getting the line with... (5 Replies)
Discussion started by: minifish
5 Replies

3. Shell Programming and Scripting

What am I doing wrong?

Trying to run a script as a different user (sudo userx inside the script) but after I call the script it just sits in memory until I <ctrl D>. If I do whoami before the <ctrl D> the system returns the userid that was invoked in the script. Is there any way to get around this behavior? TIA,... (3 Replies)
Discussion started by: gwfay
3 Replies

4. UNIX for Dummies Questions & Answers

What is wrong in here ???

]#PATH=/usr/bin:/etc:/bin:/boot/grub:/boot/grup/bin: /boot/solaris/bin:/sbin:/usr/openwin/bin:/usr/5bin://usr/X11/bin:/usr/apache/bin:/usr/apache2/bin:/usr/appserver/bin:... (9 Replies)
Discussion started by: microbot
9 Replies

5. Shell Programming and Scripting

SED to delete last word on line...what's wrong?

I have a line that gets pulled from a database that has a variable number of fields, fields can also be of a variable size. Each field has a variable number of spaces between them so there is no 'defined' delimiter. The LastData block is always a single word. What I want to do is delete the... (2 Replies)
Discussion started by: Bashingaway
2 Replies

6. Shell Programming and Scripting

What's wrong with my sed?

lyang0@lyang0-OptiPlex-755:~$ cat xx Settings for eth1: Supported ports: Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half... (11 Replies)
Discussion started by: yanglei_fage
11 Replies

7. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

8. UNIX for Dummies Questions & Answers

What is wrong with: echo $PATH | sed s/:/\\n/g

Hello all! I am on Mac (10.8.4) and my shell tcsh (man says version: Astron 6.17.00). Just to precise my tcsh: echo $LC_CTYPE UTF-8 I want to replace all ':' with a new line, to get all paths on one line. I don't find a way to make my shell accept the "\n" My start was: echo... (17 Replies)
Discussion started by: marek
17 Replies

9. Post Here to Contact Site Administrators and Moderators

Whether anything went wrong ?

Hi could see all the post with this old color scheme ( legacy (dark) vBulletin color scheme (unsupported)) except this post, please look at the screenshot . Looks like url parsing also some problem is there getting "Page not found" error. -- Akshay --edit-- screenshot is there in album... (18 Replies)
Discussion started by: Akshay Hegde
18 Replies

10. Shell Programming and Scripting

Same sed code prints(p) correct, but writtes(w) wrong output

Dear all, I am using sed as an alternative to grep in order to get a specific line from each of multiple files located in the same directory. I am using sed because it prints the lines in the correct order (unlike grep). When I write sed code that prints out the output I get it correct, but... (1 Reply)
Discussion started by: JaNaJaNa
1 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 08:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy