Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-12-2006, 05:53 AM   #1
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

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,
Old 07-12-2006, 06:03 AM   #2
jim mcnamara
Registered: May 2002
Posts: 964

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

Original Poster
Rep: Reputation: 0

Very kind. Exactly what I need.



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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:30 PM.

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