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.
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.
OW yes you went back to using single quotes, double quotes is what you would need..
try:
It would be inefficient though..
The awk is not producing any output since every record of file2 is contained in file1 so the output should be empty. Otherwise, what do you expect the output (you did not explicitly specify) to be?
OW yes you went back to using single quotes, double quotes is what you would need..
try:
It would be inefficient though..
The awk is not producing any output since every record of file2 is contained in file1 so the output should be empty. Otherwise, what do you expect the output (you did not explicitly specify) to be?
I remind it should be sed -i "%${line}%d" (not work) but I see you add \ before the first % and it works
Lei
---------- Post updated at 10:20 AM ---------- Previous update was at 10:06 AM ----------
this sed still can't work in some cases.
I want to delete the file2'line when the line contains the content of file1
sed cannot be made to work correctly, unless you escape every single basic regular expression metacharacter. And, since some characters are special in some situations and not in others, you cannot naively place a backslash before every one of them; you'll have to build a basic regular expression lexer and parser. Or ...
You should stop treating literal text as regular expressions. Use awk, grep, or some other tool that can treat arbitrary input as a literal string.
Here's another line in your sample data that will cause a problem:
As a regular expression, it won't match itself (because the [e] won't match the brackets themselves).
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
2. Post Here to Contact Site Administrators and Moderators
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)
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)
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)
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)
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)
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)
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)