Help to process each line in a file...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help to process each line in a file...
# 1  
Old 05-14-2008
Bug Help to process each line in a file...

Hi all,

I am storing all the fil names from a directory into a file "filenames.txt" like using awk and cut commands
base/src/file1.sc
base/src/file2.sc
base/src/file3.sc
base/src/file4.sc
base/src/file5.sc
base/src/file6.sc
base/src/file7.sc
base/src/file8.sc
base/src/file9.sc

and then I need to pick the 1st line from this file and need to grep for a particular pattern inside this and need to continue till the last record in file "filenames.txt", but I am stuck not knowing how to process each record from this file "filenames.txt"... I appreciate your effort in helping me.. Smilie
# 2  
Old 05-14-2008
one way -
Code:
while read filename
do
      grep 'what i want to find' $filename
done  < file_with_filenames_in_it

# 3  
Old 05-14-2008
Does grep pattern `cat filenames.txt` not do what you want? Note those are backticks (ASCII 96), not regular apostrophes.
# 4  
Old 05-14-2008
using for loop

for i in `cat filenames.txt`
do
..
grep .......... $i
..
done

Using while loop

while read line
do
..
grep ....... $line
..
done < filenames.txt



Thanks
Penchal
# 5  
Old 05-14-2008
cat filenames.txt | xargs grep pattern
# 6  
Old 05-14-2008
Thanks everyone for your quick response, I will try the solutions provided and will post the response... Smilie
# 7  
Old 05-14-2008
Quote:
Originally Posted by penchal_boddu
cat filenames.txt | xargs grep pattern
That's a Useless Use of Cat.

Code:
xargs grep pattern <filenames.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Process a file for line count using for loop in awk

Hi, I have a file with contents So what I have to do is In short, break the file after every 6 lines and then truncate new line to tab for these 6 lines. I am not able to execute the for loop in awk properly. The idea is something like this: less file| awk '{for .... {if ((nr>=1)... (7 Replies)
Discussion started by: rossi
7 Replies

2. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

3. Shell Programming and Scripting

How to process only new line of tail -f command from live log file?

Hi, I want to read a live log file line by line and considering those line which are newly added to file Below code I am using, which read line but as soon as it read new line from log file its starts processing from very first line of file. tail -F /logs/COMMON-ERROR.log | while read... (11 Replies)
Discussion started by: ketanraut
11 Replies

4. Shell Programming and Scripting

Help to process line by line and assign value to variables

Hi, there I have a file with tab and space as field separator. I need to assign values to variables then work with them, line by line. The code I wrote only works when each line has only one word. It doesn't work for the current situation. for line in `cat file.txt`; do ID=`awk '{print... (4 Replies)
Discussion started by: cwzkevin
4 Replies

5. Shell Programming and Scripting

How to process log file line by line?

Greetings, I'm new to this forum, also new to shell script I have done some simple shell script before, like backup linux machine using rsync and crontab, but now I need to do some log analyzing, which is beyond my ability... so I'm going to seek for help in this forum, hope someone could give... (5 Replies)
Discussion started by: lunaticdawn
5 Replies

6. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

7. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

8. Shell Programming and Scripting

How to read/process a .gz file, one line at a time?

Hello I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions. I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep... (2 Replies)
Discussion started by: dayscripter
2 Replies

9. UNIX for Dummies Questions & Answers

shell script to process file line by line

Hi , I am new to shell scripting (ksh shell) and trying to accomplish few requiremtns. I have a file with the following format EMP NO EMP NAME AGE Amt Paid 12 Mark Taylor 32 32333 14 James Brown... (5 Replies)
Discussion started by: royalsing
5 Replies

10. Shell Programming and Scripting

Process file line by line

Hi I have a csv file as follows 608, Barnwood PFS,,2 150, Barnwood CS,2,4 etc When i do for lines in `cat file.dat` the space in second argument seems to screwing the lines up. Any suggestions to get around this? Thanks (5 Replies)
Discussion started by: handak9
5 Replies
Login or Register to Ask a Question