search within the file in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search within the file in script
# 8  
Old 05-17-2010
Quote:
Originally Posted by Maya_Pillai
Gives error. The file names have no extensions here.

$ gawk -F"[<>]" '/Product Value/{getline;if(match($3,"GSM"))print FILENAME;nextfile}' *


gawk: not found

$ awk -F"[<>]" '/Product Value/{getline;if(match($3,"GSM"))print FILENAME;nextfile}' *

awk: syntax error near line 1
awk: illegal statement near line 1
Use nawk or /usr/xpg4/bin/awk on Solaris.
# 9  
Old 05-17-2010
This also gives error with the first file.
ACCESS_POLICY_MANAGER
nawk: illegal statement
input record number 146, file ACCESS_POLICY_MANAGER
source line number 1
# 10  
Old 05-17-2010
Remove the nextfile statement from the code if you don't use gawk:
Code:
nawk -F"[<>]" '/Product Value/{getline;if(match($3,"GSM"))print FILENAME}' *.xml

# 11  
Old 05-17-2010
Which operating systems are you using?
gawk is GNU awk and you may have to install it if you are not using Linux. On Linux awk is gawk.

zaxxon's approach may fail if the xml files are big. grep has limitation on length of line it can process.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

2. Shell Programming and Scripting

Exclude file from a search script

Hello, I use the following script to delete files from folders. There is an old file I wish to exclude the deletion script. How to exclude a file by name? Current script: ============================= #!/bin/ksh # ---------------------------------------------------- #... (1 Reply)
Discussion started by: pointer
1 Replies

3. Shell Programming and Scripting

Script to search a large file with a list of terms in another file

Hi- I am trying to search a large file with a number of different search terms that are listed one per line in 3 different files. Most importantly I need to be able to do a case insensitive search. I have tried just using egrep -f but it doesn't seam to be able to handle the -i option when... (3 Replies)
Discussion started by: dougzilla
3 Replies

4. Shell Programming and Scripting

To search a file for a specific word in a file using shell script

Hi All, I have a sql output file has below. I want to get the values 200000040 and 1055.49 .Can anyone help me to write a shell script to get this. ACCOUNT_NO ------------------------------------------------------------ BILL_NO ... (8 Replies)
Discussion started by: girish.raos
8 Replies

5. Shell Programming and Scripting

Script which will search for a file for 15 mins

Hi All, I would like to write a script which will search a file say abc.dat in /a/b/data for 15 mins only. If the script finds the file in 15 mins then it will exit will exit sucessfully and if there is no file for 15 mins it will exit and copy the last day file (abc.dat_ddmmyyhhmmss) from... (1 Reply)
Discussion started by: chandancsc
1 Replies

6. UNIX for Dummies Questions & Answers

Shell script to search for text in a file and copy file

Compete noob question.... I need a script to search through a directory and find files containing text string abcde1234 for example and then copy that file with that text string to another directory help please :eek: (9 Replies)
Discussion started by: imeadows
9 Replies

7. Shell Programming and Scripting

script to search a file

hi all i have a requirement to write a script which will serach a file in a particuar location for 3 hours from the time when the script is run.if during this period the file arrives in a particular location then this will transmit the file to a other server.please help me writing the script which... (1 Reply)
Discussion started by: dr46014
1 Replies

8. Shell Programming and Scripting

search for the contents in many file and print that file using shell script

hello have a file1 H87I Y788O T347U J23U and file2 J23U U887Y I99U T556U file3 I99O J99T F557J file4 N99I T666U R55Y file5 H87I T347U file6 H77U R556Y E44T file7 Y788O K98U H8I May be using script we can use file1 to search for all the files and have the output H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies

9. Shell Programming and Scripting

File search for pattern - script

Hi All, I have two directories as 1) mi/job -> job1.sh, job2.sh, job3.sh 2) mi/sysin -> sysin1, sysin2, sysin3,sysin4 I want to wrrite a script such that it should accept two parameters as directory paths. $ myscript mi/sysin mi/job. The script should be able to scan all files... (3 Replies)
Discussion started by: rahulrathod
3 Replies

10. Shell Programming and Scripting

Search File Script

Nice forum for noobs like me to UNIX. With that said, I need assistance. I am trying to make a script to search files for a specific date and string within the file. Then I need the script to move the file that have the specific date and string to a directory. In the interim I have been manually... (7 Replies)
Discussion started by: I4ce
7 Replies
Login or Register to Ask a Question