The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grepping the last 30 minutes of a log file... jtelep Shell Programming and Scripting 2 03-06-2008 12:27 AM
Help needed in removing intermediate segments from a pipe delimited segment file naren_0101bits Shell Programming and Scripting 3 12-03-2007 11:54 AM
Grepping Errors in a file achararun Shell Programming and Scripting 4 02-05-2007 03:36 AM
grepping a part of filenames jazz Shell Programming and Scripting 11 10-18-2006 09:03 PM
grepping the first 3 characters from a file g-e-n-o UNIX for Dummies Questions & Answers 2 10-15-2001 07:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-07-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question Grepping for filenames containing value in specific segment within file

I am trying to grep for filenames containing a specific value within a particular segment. The lines containing the segment I'm looking through reads like "HL^1^^1^1", "10^9^9^0", and "HL^11^4^8^1". I would like to find the data that contains only the number nine after the third caret where the line begins with the phrase "HL". I've tried ranges with
Code:
grep -l ^HL\^[range]\^[range]\^9

, etc. but not every filename that should be returned are being reported. The values following the first and caret do not have a fixed range, nor is there a set number of how many characters will be contained there. Please help. Thanks!
  #2 (permalink)  
Old 08-08-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
What if
$ grep -l ^HL\^[0-9]*\^[0-9]*\^9
  #3 (permalink)  
Old 08-08-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Talking

Quote:
Originally Posted by Hitori
What if
$ grep -l ^HL\^[0-9]*\^[0-9]*\^9
Thank you! It works like a charm. Thanks again!
  #4 (permalink)  
Old 08-09-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
I would like to put together something that will use the mentioned criteria, and have a specific prefix be appended to the beginning of the filename if it contains the particular string of text I am looking for. I've several approaches in mind, but they are all manual, and I would like to get to the point where I can script this. Would someone be able to point me in the right direction to accomplish this please? Thanks.
  #5 (permalink)  
Old 08-10-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360

Code:
#!/bin/sh

grep -l ^HL\^[0-9]*\^[0-9]*\^9 * 2>/dev/null | while IFS= read vo
do
mv "$vo" prefix"$vo"
done

Note: cd first to the directory where the files were placed
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0