LinuxQuestions.org
Visit Jeremy's Blog.
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 07-12-2006, 05:53 AM   #1
bryan.out.there
LQ Newbie
 
Registered: May 2006
Posts: 6

Rep: Reputation: 0
find a string followed by any word character in bash


Hi World,

In my bash script below how do I search my string for LINE: followed by any numbers, letters and hyphens so that it'll find something like LINE:A12-345. With the next line I can remove the LINE: part without a problem - just can't get the search part correct.

if [ ${temp[$i]} == "LINE*" ] ; then
linename=${temp[$i]#"LINE:"}
fi


Secondly, in order to avoid overwriting files I'm appending a -1, -2, -3 etc but doing a specific search for this.
In awk, how does one read a filename, check to see if there's a -x at the end, and if so, split that off to a variable and increment it by one for naming the next file.

Something like:

if [ ! -e $linename".sgy" ] ; then
cp $file $linename".sgy"

elif [ -e $linename"-"[1-9]*".sgy" ] ; then
do something



Thanks for any advice,
Bryan.
 
Old 07-12-2006, 06:03 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Use grep. Here's an example that assume LINE is at the start - the ^ does that:
Code:
if [[ `echo "${tmp[$i]}" | egrep -q '^LINE:[A-Z,0-9]*'; echo $?` = "0" ]] ; then
    -found it
else
    -- found it not
fi
 
Old 07-12-2006, 06:36 AM   #3
bryan.out.there
LQ Newbie
 
Registered: May 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Jim,

Very kind. Exactly what I need.

Regards,
Bryan.
 
  


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 scripting capitalizing first letter or each word in a string hypexr Programming 6 06-16-2011 09:58 AM
Remove last character from file/string linuxchump Programming 34 06-08-2009 04:01 AM
Read a word in a string with bash orgazmo Programming 6 06-07-2005 10:19 AM
Java: Change first character in word to upper AMMullan Programming 4 04-05-2004 03:16 PM
function won ' t return character array word Linh Programming 1 07-31-2003 06:11 PM


All times are GMT -5. The time now is 02:39 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration