- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: grep script
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
08-25-2002 11:50 PM
08-25-2002 11:50 PM
I would like to grep patterns in "file_1.txt" which has the format below, in the file "original.txt" i.e I would like to see if patterns in "file_1.txt" does exist in "original.txt"
#cat file_1.txt
/fs10/my_design
/fs12/schematics
/fs36/optimization
/fs20/shark
#cat original.txt
/fs10/my_design
/fs34/my_Circuits
/fs12/schematics
/fs15/layouts
I wrote a script to check if the patterns in file_1.txt does actually exist in original.txt:
#cat myscript.sh
for i in `cat file_1.txt`
do
cat original.txt|grep $i|tee -a foundPatterns.txt
done
Unfortunately, it does not grep the patterns in "file_1.txt" out from the file "original.txt" although it does exist.
However, when I did a:
#grep "/fs10/my_design" original.txt
/fs10/my_design
it then prints the contents in "original.txt" which matches the pattern specified.
Could someone show me how the script should have been written?
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:10 AM
08-26-2002 12:10 AM
Re: grep script
This should work (i called the files a and b in my test).
# while read a
> do
> grep $a b
> done /fs10/my_design
/fs12/schematics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:10 AM
08-26-2002 12:10 AM
Re: grep script
I did this ...
$more myscript.sh
for i in $(cat file_1.txt)
do
cat original.txt | grep $i | tee -a foundPatterns.txt
done
$./myscript.sh
/fs10/my_design
/fs12/schematics
$more foundPatterns.txt
/fs10/my_design
/fs12/schematics
... which is - imho - exactly what it should be ... or am I missing the point here ?
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:37 AM
08-26-2002 12:37 AM
Re: grep script
I did exactly what you did i.e:
#!/bin/sh
for i in $(cat file_1.txt)
do
cat original.txt|grep $i|tee -a foundPatterns.txt
done
but I'm still unable to find the patterns in original.txt which matches those in file_1.txt.
Could you help me out?
Thanks
CJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:45 AM
08-26-2002 12:45 AM
Re: grep script
--------------------------
for i in `cat /tmp/file.txt`
do
grep "$i" /tmp/original.txt
done
--------------------------
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 12:55 AM
08-26-2002 12:55 AM
Re: grep script
Very strange.
I altered the script just a little, but basically it SHOULD work. I attached myscript. Can you execute it ? Can you also execute with "sh -x myscript.sh" and post the output ?
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 05:17 AM
08-26-2002 05:17 AM
Re: grep script
SIMPLE:
# grep -f file_1.txt original.txt
/fs10/my_design
/fs12/schematics
# cat file_1.txt
/fs10/my_design
/fs12/schematics
/fs36/optimization
/fs20/shark
# cat original.txt
/fs10/my_design
/fs34/my_Circuits
/fs12/schematics
/fs15/layouts
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 05:18 AM
08-26-2002 05:18 AM
Re: grep script
These could prevent a match.
Rich
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 06:03 AM
08-26-2002 06:03 AM
Re: grep script
i think the grep command will do what you want. Try the follwing:
grep -f file_1.txt original.txt
This should give you all entries from file_1.txt which appear in original.txt.
If needed you could add the -x option for eXact matches.
Hope this helps.
Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 06:06 AM
08-26-2002 06:06 AM
Re: grep script
Harry was faster with exactly the same answer.
Although i was second, i hope our answers will help.
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2002 07:22 AM
08-26-2002 07:22 AM
Re: grep script
I only read the first few replys. I think the problem with using grep is that there are meta characters in the grep (like - / $ spaces etc).
You might like to alter you script subtly and do
#cat myscript.sh
for i in `cat file_1.txt`
do
grep "$i" original.txt|tee -a foundPatterns.txt
done
Regards
Tim