Grepping for filenames containing value in specific segment within file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping for filenames containing value in specific segment within file
# 1  
Old 08-07-2006
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  
Old 08-08-2006
What if
$ grep -l ^HL\^[0-9]*\^[0-9]*\^9
# 3  
Old 08-08-2006
Computer

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  
Old 08-09-2006
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  
Old 08-10-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash shell script not working-picking segment patterns from a file

Hi All, I have to pick particular segments from a file and I have prepared below shell script.But its not working and I am not able to find out whats the issue.could you guys pls help? Sample file: TS3*1451575*12*20151231*4*482.44 NM1*QC*1*CUTLER*BETTY DTM*472*20150808... (4 Replies)
Discussion started by: Venkata Prasad
4 Replies

2. Shell Programming and Scripting

Printing next two lines from a file after grepping a specific pattern

Hi I have a file like # vi require.txt 1,BANK,Read blocks that cycle. yellow Read blocks. 2,ACCOUNT,Finished Red Finished . 3,LOAN, pipe white pipe 4,PROFIT,Resolve. black Resolve Am using like cat require.txt | grep -w ACCOUNTThe output I get is (8 Replies)
Discussion started by: Priya Amaresh
8 Replies

3. Shell Programming and Scripting

Grepping a specific row from a file

Hi I have output of a command saved in a file.. # cat /file.txt System: cu=4 ent=0.1 mode=on cu min u s w i 0 500 0.1 0.3 0.5 0.1 1 200 0.5 0.2 0.3 0.0 By using ksh, what I need to do is, I need to grep the u,s,w and i... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

4. Programming

Data segment or Text segment

Hi, Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment? char *a = "Hello"; I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies

5. Shell Programming and Scripting

Segment a big file into smaller ones

Greeting to all. I have big text file that I would like to segment into many smaller files. Each file should be maximum 10 000 lines. The file is called time.txt. after the execution of the file I would like to have. time_01.txt, time_02, txt, ...,time_n.txt Can anybody help. Br. (2 Replies)
Discussion started by: flash80
2 Replies

6. UNIX for Dummies Questions & Answers

Searching for specific filenames

Hi I would like to know how to search through a directory and pull out files that has a specific pattern in the filename. For example if the filename has "bsc" in it, then that file must be moved to another directory where I will perform some operations on it. I know grep can be used, but I'm... (17 Replies)
Discussion started by: ladyAnne
17 Replies

7. UNIX for Dummies Questions & Answers

Grepping A Specific Column

Hello, I have a log file that outputs the data below. I would like to grep and display the data where column is equal '148.' I've searched the forum, and couldn't find any answers. I've tried all the grep switches and I get the same result as the log. I'm thinking I might have to use an... (4 Replies)
Discussion started by: ravzter
4 Replies

8. Shell Programming and Scripting

Finiding filenames with specific index string

Hi All, I have a file (Names.txt) and the contents of the file is give below. $ cat Names.txt FF313207008.txt FF223207007.txt FF143207006.txt FF372150600.txt FF063407005.txt FF063307005.txt $ From these given file names I want to find the files which has the 6th index value as 2. So... (5 Replies)
Discussion started by: krish_indus
5 Replies

9. Programming

a large file causes segment, how to overcome?

When printing a large file, segment occured. but part of it can be printed normally. There seems no mistake in usage. How to solve the problem. Actually, the file is not very very large. Only 300-400 A4 pages. Thanks (1 Reply)
Discussion started by: cdbug
1 Replies

10. Shell Programming and Scripting

grepping a part of filenames

Hi , I have a list of files in a directory and filename format is as follows: PQ223390 PQ876912 PQ768901 PQ398140 and so on I want to grep the first four digits of all the files after PQ, into a file. Ex: 2233 8769 6890 3981 and so on Can anyone tell me the command? thankx jazz (11 Replies)
Discussion started by: jazz
11 Replies
Login or Register to Ask a Question