Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
File Pattern Matching
Name: navik_pathak Date: April 20, 2004 at 23:50:18 Pacific OS: HP-UX CPU/Ram: 1024
Above is the file name will be in respective directory. Now my first requirement is to find RFP in the above file name and if RFP is found in the file name then i have to remove date time part from it.
Name: FishMonger Date: April 21, 2004 at 00:25:53 Pacific
Reply:
Do you want to do it from the command line or script? Which language? When you say, "Now my first requirement is..", does that mean this is a homework assignment?
Here's a portion of one method. s!(?<=RFP)_\d+!!
0
Response Number 2
Name: Wolfbone Date: April 21, 2004 at 00:53:52 Pacific
both examples will strip out ANY digits from a string $str containing "RFP" which is OK for the examples you gave but not if there are other digits in the filename string.
0
Response Number 3
Name: Wolfbone Date: April 21, 2004 at 01:05:09 Pacific
Reply:
Bah! - remove the extra underscore yourself ;)
0
Response Number 4
Name: Wolfbone Date: April 21, 2004 at 01:32:18 Pacific
Reply:
Double Bah! - replace tr -d 'RFP' in the 2nd version with sed 's/RFP//'
0
Response Number 5
Name: navik_pathak Date: April 21, 2004 at 03:29:18 Pacific
Reply:
Hi Wolford,
First Of all i am using K Shell.
I am doing this thing in Shell script not at command line
Prashant Pathak
0
Response Number 6
Name: Wolfbone Date: April 21, 2004 at 04:48:52 Pacific
Reply:
Well Hi Prashant :) - It won't make a great deal of difference if it's in a script or at the command line.
I'm not very familiar with the Korn but a quick look at the manual seems to indicate that the (amended) 2nd version may work in that environment too.
0
Response Number 7
Name: Wolfbone Date: April 21, 2004 at 05:23:40 Pacific
Reply:
In other words, if in your shellscript you've got the file name into the variable filename, this line should transform it according to your rules:
Summary: Do you need to delete the lines that include the patterns or just the lines inbetween? This perl command will do an inline edit of your file and delete the inbetween lines as well as the pattern matc...
Summary: If you are calling sed every time through the loop, there is no way it is more efficient. If you are doing a global change to a file, sed is the utility of choice. Size of the file is not a factor. ...
Summary: Hi, I want to delete files which had been created 2 days ago having names like: er_n5412_output_yyyymmdd.csv.processd from the directory /opt/apps/ccba/dev/callftp/cps_adhoc. There will be several ot...