LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-16-2010, 07:25 PM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
BASH: while true to "read" a file


Jog my memory somebody -- Google evidently has no idea what I mean.

I had a script once that had in it a while true; do and read lines or data from a file similarly to a while read; do. I have a script I'm working on now where I'm trying to "prove the negative" that certain substrings culled from one file do not appear in another file.

I'll try to explain what I mean with an example.

An item in one list might be
Code:
harvey1998nicks211.jpg
But the other list may only have
Code:
harvey1996nicks:Six stores in north London
harvey1997nicks:Three stores in Bristol
harvey1999nicks:Eight stores in the lower Midlands
The problem is, other items in the first list do match items in the second. The script I'm drawing this from has already pulled those out and written them to one (or several) lists that I've been able to use with other programs (Exiv2 specifically).

The furthest I've bothered to go in the direction of "proving the negative" is a slow "if/then/fi" loop that looks like this:
Code:
linecheck=$[linecheck+1]
if [[ "$linecheck" == "$axe" ]] && [[ "$matchX" == "" ]]; then echo -e $file>>nomatches.txt; fi
linecheck is counting the lines of the second file -- the one with the designations or "labels" (the "so many stores in ..." from my example) -- as they are checked against the file names in the first (the "harvey199*nicks.jpg" etc of my example. axe is the number of lines in that first list (culled from a cat |wc -l at the beginning of the script). matchX is the variable the "prove the positive" script used for matches, one list to the other, which then got written line by line to a text file.

I have the strong feeling that either a while true do or a better-written if/then/fi loop is what I'm looking for. If there are other methods, I'll certainly entertain any suggestions in that direction.

BZT

Last edited by SilversleevesX; 09-16-2010 at 07:29 PM. Reason: Forgot to describe a variable.
 
Old 09-16-2010, 09:13 PM   #2
SilversleevesX
Member
 
Registered: May 2009
Posts: 181

Original Poster
Blog Entries: 9

Rep: Reputation: 15
It was a case for "case"

The code that saved the day:
Code:
case "$matchX" in
  "") echo -e "$file">>nomatches.txt
  ;;
  *) ;;
esac
I forgot to mention, that slow if/then/fi in the other script was also giving me no more than the first line item that met its conditions. This case/esac loop does turn out a nice long list, with a lot of duplicated lines, but I already knew how to deal with that *sort* of thing (pvmi):

Code:
sort -t"/" -k6 -u nomatches.txt -o notamatch.txt
rm nomatches.txt
mv -v notamatch.txt nomatches.txt
Sometimes a forum serves well just to help one sort things out in print & in "public." It gets one thinking faster and harder, at any rate.

BZT
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: How to running several "Read" commands at the same time? CrAzYoNi Programming 3 03-12-2009 08:30 AM
if [ "$VAR"="string" ] always testing TRUE JohnE1 Programming 2 08-05-2008 08:35 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 09:00 AM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration