- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to grep for tab spaces?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 09:43 AM
02-21-2006 09:43 AM
How to grep for tab spaces?
I have another file with 100 lines in it.
I want to remove lines from the 25k file that contain the line from the 100 line file.
25k file is like this
nnnnn
the 100 line file just has the xxxxxx entry
the problem with just using grep is that many lines could contain the word in the 100 line file, but I just want to remove the record that has
ex:
25K file
12345
2245
100 line
car
boat
apple
I only want to remove
2245
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 09:52 AM
02-21-2006 09:52 AM
Re: How to grep for tab spaces?
Based upon your last comment:
# perl -lne 'print unless m{\b2245\tcar\temail1\b}' yourfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 09:58 AM
02-21-2006 09:58 AM
Re: How to grep for tab spaces?
perl -ane 'print $_ if $F[1] eq "car"' yourfile
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 09:59 AM
02-21-2006 09:59 AM
Re: How to grep for tab spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:00 AM
02-21-2006 10:00 AM
Re: How to grep for tab spaces?
grep -E -v -e '
You could also anchor your string for even better matching:
grep -E -v -e '^[0-9]+
Note:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:01 AM
02-21-2006 10:01 AM
Re: How to grep for tab spaces?
Note:
Ok, by this do you mean \t ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:01 AM
02-21-2006 10:01 AM
Re: How to grep for tab spaces?
cat myfileof25klines | grep "\
yields the lines with
(
HTH
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:04 AM
02-21-2006 10:04 AM
Re: How to grep for tab spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:05 AM
02-21-2006 10:05 AM
Re: How to grep for tab spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:05 AM
02-21-2006 10:05 AM
Re: How to grep for tab spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:16 AM
02-21-2006 10:16 AM
Re: How to grep for tab spaces?
XX=$(echo "\011car\011")
grep -E -v -e "${XX}" < infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:27 AM
02-21-2006 10:27 AM
Re: How to grep for tab spaces?
#!/bin/ksh
for USER in `cat /tmp/test`
do
echo $USER
grep -E -v -e' $USER ' < /tmp/emails.lst > /tmp/emails.out
cp -f /tmp/emails.out /tmp/emails.lst
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:35 AM
02-21-2006 10:35 AM
Re: How to grep for tab spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 10:52 AM
02-21-2006 10:52 AM
Re: How to grep for tab spaces?
OK, if you have a file with 100 tokens, each of which you want to delete from your first file then:
Assuming that the first file pattern is defined as some digits followed by a tab, followed by a token (specified in the second file) followed by another tab, like:
...then:
# cat ./perl.pl
#!/usr/bin/perl
use strict;
use warnings;
my %line;
my $key;
my $token;
my $file1=shift or die;
my $file2=shift or die;
open (FH, "<", $file1) or die "Can't open $file1: $!\n";
while (
chomp;
$line{$.}= $_;
}
close(FH);
open (FH, "<", $file2) or die "Can't open $file2: $!\n";
while (
chomp;
$token = $_;
foreach $key (keys %line) {
if ($line{$key} =~m/^\d+\t$token\t/) {
delete ($line{$key});
}
}
}
foreach $key (sort keys %line) {
print "$line{$key}\n";
}
1;
Run this as:
# ./perl.pl datafile tokenfile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 01:26 PM
02-21-2006 01:26 PM
Re: How to grep for tab spaces?
[root@fishgeeks tmp]# cat /usr/local/bin/sean/cleanemails.lst
#!/usr/bin/perl
use strict;
use warnings;
my %line;
my $key;
my $token;
my $file1=shift or die;
my $file2=shift or die;
open (FH, "<", $file1) or die "Can't open $file1: $!\n";
while (
chomp;
$line{$.}= $_;
}
close(FH);
open (FH, "<", $file2) or die "Can't open $file2: $!\n";
while (
chomp;
$token = $_;
foreach $key (keys %line) {
if ($line{$key} =~m/^\d+\t$token\t/) {
delete ($line{$key});
}
}
}
foreach $key (sort keys %line) {
print "$line{$key}\n";
}
1;
[root@fishgeeks tmp]# /usr/local/bin/sean/cleanemails.lst /tmp/emails.lst /tmp/test > /tmp/emails.out
ll em*
cat emails.lst | wc -l
[root@fishgeeks tmp]# ll em*
-rw-r--r-- 1 root root 1004259 Feb 21 20:20 emails.lst
-rw-r--r-- 1 root root 1004259 Feb 21 20:25 emails.out
[root@fishgeeks tmp]# cat emails.lst | wc -l
24594
[root@fishgeeks tmp]# cat emails.out | wc -l
24594
[root@fishgeeks tmp]# head emails.lst
17779 : gemma : 03goodenoughgem@upperavon.wilts.sch.uk
17322 : Luanne : 11402@aol.com
8101 : 123 : 123@aol.com
15075 : Krokodil : 12794201@puknet.puk.ac.za
17655 : jc : 14337983@sun.ac.za
17656 : mariska : 14378574@sun.ac.za
17350 : 1charmed1 : 1charmed1@sympatico.ca
15765 : chester : 1doglover@sbcglobal.net
17654 : ksehler : 1forme@earthlink.net
24700 : cripps72 : 1fullyinvolved@charter.net
[root@fishgeeks tmp]# head test
ccotu
AngelaDickson
bato
pamrobi
capnben
basheeba
Terrymobil
gem
recycling=goddess
tinfoilowner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 03:04 PM
02-21-2006 03:04 PM
Re: How to grep for tab spaces?
perl -ane 'BEGIN{open(INP,"<100linefile"); @a=
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 03:11 PM
02-21-2006 03:11 PM
Re: How to grep for tab spaces?
grep -Evf 100linefile 25kfile > new25kfile
mv new25kfile > 25kfile.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2006 03:16 PM
02-21-2006 03:16 PM
Re: How to grep for tab spaces?
#!/bin/ksh
for USER in `cat /tmp/test`
do
echo $USER
grep -E -v -e' $USER ' < /tmp/emails.lst > /tmp/emails.out
can't possibly work. Why? Because variables within sigle quotes are not expanded so that ' ${USER} ' is just exactly that. The solution is DOUBLE quotes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2006 09:12 PM
02-22-2006 09:12 PM
Re: How to grep for tab spaces?
this is run fine on my server with korn shell:
1.
sed 's/^/ /;s/$/ /' 100line>100line.new
This will create a file 100line.new with the user name eclosed in tabs. Plead note that you have to substitute the space in the above comamnd type TAB on you keyboard
2.
grep -vf 100line.new 25Kfile>25Kfile.new
this will obtain what you want
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2006 10:14 PM
02-23-2006 10:14 PM
Re: How to grep for tab spaces?
if you like an awk-solution:
awk -F' ' -v pat=100lines 'BEGIN {while ((getline < pat) == 1) m[$0]=$0; close (pat)}
NF>3 {out=1; for (p in m) {if (p==$2) {out=0;break}}; if(out) print}' logfile
mfG Peter