grep part of file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep part of file name
# 1  
Old 05-12-2009
Error grep part of file name

Hi,

I have a problem to use grep in my script .

If I want to grep the file for example : PTWO9089.txt
The code below works .
grep ^PONE

But, I dont know on how to grep the file like this 9066PTWO.txt
I'll try to use this code :
grep PTWO^ ,but it doesn't work.

For your info, the number will always change. Hope you guys can help me.
Thanks You.
# 2  
Old 05-12-2009
Code:
grep ".*PTWO"

to be more specific
Code:
grep -E ".*(PTWO)\.(txt)$"



"^" is used to search in the beginning. therefore nothing after "^" will not work.
"$" is used to search at the end.
# 3  
Old 05-12-2009
Code:
 
ls -l  | grep PTWO

# 4  
Old 05-12-2009
Code:
ls | grep "*PTWO*.txt"



cheers,
Devaraj Takhellambam
# 5  
Old 05-12-2009
no need to use ls and grep together for this case
Code:
ls *PWTO*.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. UNIX for Beginners Questions & Answers

Grep a section from an UNIX file obtaining only part of the data

Hello, I have a log file that has several sections "BEGIN JOB, End of job" like in the following example: 19/06/12 - 16:00:57 (27787398-449294): BEGIN JOB j1(27787398-449294) JOB1 19/06/12 - 16:00:57 (27787398-449294): DIGIT: 0 number of present logs : 1 19/06/12 - 16:00:57... (4 Replies)
Discussion started by: mvalonso
4 Replies

3. UNIX for Dummies Questions & Answers

Grep a part of a line from a file

Hi, I have a file with thousands of lines as below INSERT INTO T_DIM_CLNT(CLNT_KY,CLNT_OBJ_ID,ISI_CLNT_ID,OPERN_ID,CLNT_NM,PRMRY_SIC_CD,PRMRY_SIC_DSC,RET_AGE_NBR,REC_CRT_TS,REC_DATA_EXTRC_TS,ETL_LOG_KY) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)... (5 Replies)
Discussion started by: sudhakar T
5 Replies

4. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. Shell Programming and Scripting

[awk] grep a part of filename as entry file

hi all, i need to combine these files into one csv file. Bounce_Mail_Event_Daily_Report_01_Jul_2012.csv Bounce_Mail_Event_Daily_Report_02_Jul_2012.csv Bounce_Mail_Event_Daily_Report_03_Jul_2012.csv Bounce_Mail_Event_Daily_Report_04_Jul_2012.csv... (10 Replies)
Discussion started by: makan
10 Replies

7. UNIX for Dummies Questions & Answers

can I grep a part of one line ?

<exp code="12556a" message="ok, fine4" displayMessage="jksdfj ksd" \> <exp code="123456a" message="ok, 2fine" displayMessage="jksdfj ksd" \> <exp code="12dfgda" message="1ok, fine" displayMessage="jksdfj ksd" \> now I want to cut code attribute and message attribute, such as ... (2 Replies)
Discussion started by: vincent_W
2 Replies

8. Shell Programming and Scripting

How to get a part of the line(need help in using grep)

Hi, Suppose, DBconnection=jdbc: oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=x.x.x.x)(PORT=YYYY))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=project_db1))) This is a part of a file <filename> . I Need to get the value of SERVICE_NAME from this line… The... (4 Replies)
Discussion started by: Dpu
4 Replies

9. UNIX for Dummies Questions & Answers

How to use grep to get only part of a line...

Hello All. I have an output file which contains the phrase "Total DFT Energy =" and then a number. This occurs many times in the output file, and what I want is to pipe the numbers (which are all different) to a file so I can plot them. How do I grep "Total DFT Energy =" and then get the numbers... (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

10. UNIX for Dummies Questions & Answers

grep within certain part of file

Hi, Is it possible to grep only on a certain part of a file? Say I have file in.txt which contains below: 11/16 13:07:19.5436 --- ERROR 123 detected. 11/16 13:08:19.5436 --- Generating a <reading> event 11/16 13:08:19.7784 ---- Sending a <writing> event 11/16 14:08:37.4516 ---... (2 Replies)
Discussion started by: Orbix
2 Replies
Login or Register to Ask a Question