Sponsored Content
Full Discussion: grep vs do while read
Top Forums Shell Programming and Scripting grep vs do while read Post 302281788 by Corona688 on Thursday 29th of January 2009 12:26:41 PM
Old 01-29-2009
Yes, csh is very different from sh, and you're doing well to avoid it.

Code:
RECORDS = `grep ^$1 ${CFGFILE} | grep 'C$'`
for record in ${RECORDS}
do
        rSID = `echo $record | tr -s " " | cut -f1 -d","`
        rCLIENT = `echo $record | tr -s " " | cut f2 -d","'
        rINSTANCE = `echo $record | tr -s " " | cut -f3 -d","`
        rSERVER = `echo $record | tr -s " " | cut -f4 -d","`
        rTYPE = `echo $record | tr -s " " | cut -f5 -d","` 
done

This is just a direct transliteration, as inelegant as it started as. There's probably a better way, avoiding the creation of 15 superfluous processes if we knew exactly what this script did.

Last edited by Corona688; 01-29-2009 at 01:32 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file then grep the line

Dear all, I am reading a file that has 1 column. While reading I must find the line references from the another file. The following shell doesn't works. Please help #!/bin/bash while read filename; do grep ${filename} fs_full.dat >> unprocfull.dat; done < unproc.dat But when... (2 Replies)
Discussion started by: mr_bold
2 Replies

2. UNIX for Dummies Questions & Answers

Using the Read command with grep

I am still fairly new to unix scripting and I will try my best to explain my question the best I can.... I have a text file called hello.txt, and in this file I need to search every line that contains the words "help" and "cat" and move the respective lines into their own columns in another... (2 Replies)
Discussion started by: silvermax
2 Replies

3. Shell Programming and Scripting

grep within while read loop

I have a key file $ cat klist 5 N:8855 CASA VERDE ROAD :32827 :ORLAND 5 N:585 MOLLY LANE :30189 :WOODST 5 N:320 NINA ROAD :32304 :TALLAH and a data file, see example of the line below: N:RT 15 & N 7TH STREET :17837 :U SAVE I need to search by key (2nd field) from klist... (6 Replies)
Discussion started by: migurus
6 Replies

4. Shell Programming and Scripting

read the first 10 lines below a keyword found by grep

Hello Everyone, i need to read specific number of lines ( always serialized ; i.e from 10 to 20 or from 34 to 44 ) in a file , where the first line is found by grep 'ing a keyword. example file.txt ------------------------------------------------------------------ --header this is the... (7 Replies)
Discussion started by: alain.kazan
7 Replies

5. Shell Programming and Scripting

Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file. I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com) My script sends... (7 Replies)
Discussion started by: binary-ninja
7 Replies

6. UNIX for Dummies Questions & Answers

Strange error: grep does not read from file

I have two files file1.txt angie mary susan file2.txt angie blond mary brunnet susan red christine blackI want to get this output angie blond mary brunnet susan redI write grep --file=file1.txt file2.txtand i get no results i also wrote cat file1.txt|while read line... (19 Replies)
Discussion started by: FelipeAd
19 Replies

7. Shell Programming and Scripting

read from file and grep using shell

Hi Guys, I have a small script which greps for the username reading from stdinput. ./file.sh pattern pattern=$1 grep "blah blah.*$pattern" /home/user/log.txt Instead of typing the pattern everytime i want to read the pattern from a file inside the shell script and execute the... (5 Replies)
Discussion started by: Irishboy24
5 Replies

8. Shell Programming and Scripting

How to grep and count the occurences in while read script?

Hi, I have a file while is the output of lspath command and output of file is #cat lspath.txt Enabled hdisk0 vscsi0 Enabled hdisk0 vscsi1 Enabled hdisk1 vscsi0 Enabled hdisk2 vscsi0 Enabled hdisk2 vscsi1 Missing hdisk3 vscsi0 Enabled hdisk3 vscsi1 Have created script to check state... (7 Replies)
Discussion started by: ksgnathan
7 Replies

9. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

10. Shell Programming and Scripting

How to read each file grep a value from that?

Hi Team, in /tmp folder i have thousands of log files i want to read each file and grep a value called "Calling This". Each logfile name is different but it ends with .log. How can i achieve this? Please excuse if i did any mistake by not following forum standards. I will surely follow... (10 Replies)
Discussion started by: darling
10 Replies
ZGREP(1)						    BSD General Commands Manual 						  ZGREP(1)

NAME
zgrep, zegrep, zfgrep -- print lines matching a pattern in gzip-compressed files SYNOPSIS
zgrep [grep-flags] [--] pattern [files ...] zegrep [grep-flags] [--] pattern [file ...] zfgrep [grep-flags] [--] pattern [file ...] DESCRIPTION
zgrep runs grep(1) on files or stdin, if no files argument is given, after decompressing them with zcat(1). The grep-flags and pattern arguments are passed on to grep(1). If an -e flag is found in the grep-flags, zgrep will not look for a pattern argument. zegrep calls egrep(1), while zfgrep calls fgrep(1). EXIT STATUS
In case of missing arguments or missing pattern, 1 will be returned, otherwise 0. SEE ALSO
egrep(1), fgrep(1), grep(1), gzip(1), zcat(1) AUTHORS
Thomas Klausner <wiz@NetBSD.org> BSD
December 28, 2003 BSD
All times are GMT -4. The time now is 07:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy