sed -e 's;^/a/b/c;' <file1 >file1a
cat a.txt a.txt b.txt | sort | uniq -u # if -u is correct, sort correct ...
kclark said:Weird question. I have a file with several thousand lines in it. Each line is a path to a file. Is there a simple way to remove all lines that don't include "/a/b/c/" in them.
grep '/a/b/c' originalfile > otherfile
jalla said:No need to muck around with ed, sed, etc.
Code:grep '/a/b/c' originalfile > otherfile
grep -v '/a/b/c' originalfile > otherfile
fluca1978 said:Should be:
Code:grep -v '/a/b/c' originalfile > otherfile
to get the lines that do not contains /a/b/c as asked in the original post.
Anyway, this is of course possible with pretty much any text editor available on Unix (Emacs for instance), but the command line is usually the right and most automated way of doing such text manipulation.
For more complex text manipulation Perl can come in hand.
jalla said:You may want to read the original post again![]()
PugTsurani said:Use comm(1) to show lines in one file but not the other. This command will output two tab-separated columns: lines only in a.txt and lines only in b.txt. Column 3 contains lines in both files and is suppressed by the -3 option. I have a hard time remembering it's subtractive, not additive. The only requirement is that both files need to be sorted.
[cmd=""]comm -3 a.txt b.txt[/cmd]
shells/bash's process substitution can be used to combine grep with comm in a single command. The first Google hit for "bash process substitution" contains an example using comm: http://tldp.org/LDP/abs/html/process-sub.html. Remember, both inputs need to be sorted.
[cmd=""]comm -3 <(grep '/a/b/c' a.txt | sort) <(sort b.txt)[/cmd]
Since comm uses a tab to separate the two columns representing each file, sed can be used to remove the leading and trailing tab output for file b.txt and a.txt respectively. Use ctrl-v <tab> to enter a literal tab in the command line. The space in the first command is actually a tab, shown as TAB in the second command.
[cmd=""]comm -3 <(grep '/a/b/c' a.txt | sort) <(sort b.txt) | sed -e 's/^ //g; s/ $//g'[/cmd]
[cmd=""]comm -3 <(grep '/a/b/c' a.txt | sort) <(sort b.txt) | sed -e 's/^TAB//g; s/TAB$//g'[/cmd]
Cheers!
diff <(sort list1) <(sort list2)
mkfifo /var/tmp/fifo1
mkfifo /var/tmp/fifo2
sort list1 >/var/tmp/fifo1 &
sort list2 >/var/tmp/fifo2 &
diff /var/tmp/fifo1 /var/tmp/fifo2
rm /var/tmp/fifo1 /var/tmp/fifo2
Process substitution is definitely not portable. You may use NamedPipes to accomplish the same things.