Remove data from grep command using the pattern in the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove data from grep command using the pattern in the file
# 1  
Old 11-08-2012
Remove data from grep command using the pattern in the file

Hi,
I writing a shell program to remove the data from output of the find which matches a list in a file

I am using the below find command to get the list of files

x=`find . -name test*.dat`

the output of the find command is as follows

test1.dat
test2.dat
test3.dat
test4.dat
test5.dat

i have a file list.txt with the below search pattern

test4
test1


i need to remove the test4.dat and test1.dat from the variable x based on the data which is present in the file .

Kindly suggest me how to achive the same.

thanks
pals
# 2  
Old 11-08-2012
Hi,

Please use code tags for code and data samples.

The code tag look like Image in the editor.

You can try below code snippet.

Code:
while read i;do x=$(echo "$x"|sed "s/.*\/$i.dat$//"); done <list.txt

I am assuming, you using bash shell. Please make sure that you should mention what system/shell are you using.

Cheers,
Ranga Smilie
# 3  
Old 11-08-2012
try

Code:
x=$(find . -name test*.dat | grep -vf file)

# 4  
Old 11-08-2012
Code:
echo "$x" | fgrep -v -f a.txt
test2.dat
test3.dat
test5.dat

# 5  
Old 11-08-2012
Many thanks rangarasan and pamu for your help.both the command works perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter pattern in grep command

Hi, I am having a file like below hello how are you hello... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

2. Shell Programming and Scripting

Search file pattern using grep command

I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing... (7 Replies)
Discussion started by: vinus
7 Replies

3. Shell Programming and Scripting

How to grep/sed selected data from a command or file?

Below is the output of a DB2 command. Now I have 2 requirements... Database Partition 0 -- Database TESTDB1 -- Active Standby -- Up 213 days 02:33:07 -- Date 02/22/2016 17:04:50 HADR Information: Role State SyncMode HeartBeatsMissed LogGapRunAvg (bytes) Standby ... (2 Replies)
Discussion started by: rlokesh27
2 Replies

4. Shell Programming and Scripting

sed and awk usage to grep a pattern 1 and with reference to this grep a pattern 2 and pattern 3

Hi , I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows. # diff mir_lex.c.modified mir_lex.c.orig 3209c3209 < if(yy_current_buffer -> yy_is_our_buffer == 0) { --- >... (5 Replies)
Discussion started by: breezevinay
5 Replies

5. Shell Programming and Scripting

Grep command is not search the complete pattern

I am facing a problem while using the grep command in shell script. Actually I have one file (PCF_STARHUB_20130625_1) which contain below records. SH_5.55916.00.00.100029_20130601_0001_NUC.csv.gz|438|3556691115 SH_5.55916.00.00.100029_20130601_0001_Summary.csv.gz|275|3919504621 ... (2 Replies)
Discussion started by: sumit.vedi1988
2 Replies

6. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

7. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

8. Shell Programming and Scripting

Grep command with multiple pattern

Hi, I want to search multiple patterns in a variable. DB_ERR=`echo "$DB_TRANS" | grep "SP2-" | grep "ORA-"` echo $DB_ERR But I am not getting anything in DB_ERR. I want to print each line on seperate line. Could you please help me out in this. Thanks in advance. (14 Replies)
Discussion started by: Poonamol
14 Replies

9. Shell Programming and Scripting

grep for a particular pattern and remove few lines above top and bottom of the patter

grep for a particular pattern and remove 5 lines above the pattern and 6 lines below the pattern root@server1 # cat filename Shell Programming and Scripting test1 Shell Programminsada asda dasd asd Shell Programming and Scripting Post New Thread Shell Programming and S sadsa ... (17 Replies)
Discussion started by: fed.linuxgossip
17 Replies

10. UNIX for Advanced & Expert Users

grep command - excat pattern

Hi, I wanna use grep command to search the excat pattern. For eg. I want to do ps -ef | grep '6710' It should not display other than the process id 6710. i.e) It should not display 26710,16710 etc., Thanking u. (2 Replies)
Discussion started by: sharif
2 Replies
Login or Register to Ask a Question