removing part of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing part of a file
# 8  
Old 09-25-2012
Well, as we don't have an idea how your directory structure looks like, we can't tell how many files will be found below that starting dir. You may want to add the -prune action. Also, the -mtime +2 (older than now - (48h+)) is depending on the time you issue the command; it will yield different results on Monday or on Tuesday, and if issued at 10:00h in the morning or later at night.
The grep will grep filenames sa1 till sa9, but not sa10, sa15, or sa17. Use [1-9][1-9] for a two digit wildcard.
And, finally, you read filenames in the while loop, but you don't use them as a parameter for your sar.sh script; unless you are using the f variable in the script, all the filename a thrown to the bin, making the earlier commands redundant.
# 9  
Old 09-25-2012
I have sorted this out using the -exec function of the find command,
I needed to run the sar -uf command on each individual file in the /var/adm/sa directory

and using grep sa[1-9] does grep for two digits or more as the [1-9] for grep is a wildcard for all numbers not just the ones listed
# 10  
Old 09-25-2012
Sorry for my sloppy wording; you are right, it will grep sa17, but it will grep sa1A as well, should it exist.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 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. Shell Programming and Scripting

How to print the specific part of the file name with file creation date?

Hello Folks, I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern. Filename: MobileProtocol.20171228T154200.157115.udr I want to get the count of files created on each day based on a pattern find. find . -type... (7 Replies)
Discussion started by: sadique.manzar
7 Replies

3. Shell Programming and Scripting

Removing folders with specific name/part

Hi, I need a way to remove all folders that contain "Quick" in their names in a directory called /var/tmp... However all attemps I have tried won't work. :wall: I so far tried find /var/tmp -type d -name "Quick" | sudo xargs rm -rf find . -name "Quicklook" -exec rm -rf {} \; find .... (2 Replies)
Discussion started by: pasc
2 Replies

4. 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

5. Shell Programming and Scripting

Removing part of a file name and appending into a single file

I have two files like ABC_DEF_yyyyymmdd_hhmiss_XXX.txt and ABC_DEF_yyyyymmdd_hhmiss_YYY.txt. The date part is going to be changing everytime. How do i remove this date part of the file and create a single file like ABC_DEF_XXX.txt. (8 Replies)
Discussion started by: varlax
8 Replies

6. UNIX for Dummies Questions & Answers

Removing Part of a variable based on a pattern

Hi All, I am writing a script to work with files in a folder. The files are all in the following patterns (without quotes): "some filename - NxNN - the end.YYY" or "some filename - NNxNN - the end.YYY" Where N = a single number and YYY is the extension. Basically what I want... (5 Replies)
Discussion started by: sgtbobie
5 Replies

7. UNIX for Dummies Questions & Answers

Making replicates of a file with part of a line randomized for each file

Ok, so let's say that I have a file like the following: I want to create 100 replicates of this file, except that for each file, I want different randomized combinations of either A or B at the end of each line so that I would end up with files like the following: and etc. I... (1 Reply)
Discussion started by: Scatterbrain26
1 Replies

8. UNIX for Dummies Questions & Answers

sed or awk - removing part of line?

hi all, I am having trouble finding the right string for this - I dont know whether to use awk or sed.. If I have a file with alot of names and phone numbers like this McGowan,Sean 978-934-4000 Kilcoyne,Kathleen 603-555-1212 Club603,The 617-505-1332 Boyle,William 301-444-1221 And... (11 Replies)
Discussion started by: alis
11 Replies

9. Shell Programming and Scripting

rename file by removing some part of the file name

I am special requirements to rename file. I have files with names like below: 1_firstname1_lastname1.html 2_firstname2_lastname2.html 3_fistname3_lastname2.html I would like these file to be renamed as below firstname1_lastname1.html firstname2_lastname2.html... (5 Replies)
Discussion started by: McLan
5 Replies
Login or Register to Ask a Question