removing part of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting removing part of a file
# 1  
Old 09-25-2012
removing part of a file

Right this is quite a long one,
I have a script which complies all listed stats files into one file and emails it out,
However this has to be run manually and i would like it to run automatically,

I have a list of files eg

Code:
sa17
sa18
sa19
sa20
sa21

one file for each of last weeks working days,
howver I need them in this format

Code:
17 18 19 20 21

And then I need to use them as the input to a script.
any info is helpful

Last edited by radoulov; 09-25-2012 at 08:36 AM..
# 2  
Old 09-25-2012
much info on this would be appreciated.

ls sa* | sed 's/[a-z]*//g' will give you the list of files with "sa" removed.

Last edited by radoulov; 09-25-2012 at 08:36 AM..
# 3  
Old 09-25-2012
Try like..
Code:
ls sa*.txt|awk '{print substr($1,3)}'|sed  's/.txt//g'

---------- Post updated at 06:37 AM ---------- Previous update was at 06:32 AM ----------

Try like...
Code:
ls sa*.txt|awk '{print substr($1,3)}'|sed  's/.txt//g' |tr '\n' " " <

# 4  
Old 09-25-2012
Like this?
Code:
$ ls
sa17  sa18  sa19  sa20  sa21
$ ls|while read f;do echo mv $f ${f#??} && echo 'MYSCRIPT' ${f#??};done
mv sa17 17
MYSCRIPT 17
mv sa18 18
MYSCRIPT 18
mv sa19 19
MYSCRIPT 19
mv sa20 20
MYSCRIPT 20
mv sa21 21
MYSCRIPT 21

Remove the echo's if you are happy. Smilie
# 5  
Old 09-25-2012
Sorry, if I was to remove the echo's and want to run my script which is called sar.sh what should it look like?
# 6  
Old 09-25-2012
Code:
ls|while read f;do mv $f ${f#??} && sar.sh ${f#??};done

# 7  
Old 09-25-2012
right Im thinking an easier way is run a find to get all the sa files written last week and then I want to run my sar.sh script on each of these. so at the momment i have
Code:
find /var/adm/sa -type f -mtime +2 | grep sa[1-9] | while read f;do sar.sh ;done

is this ok as at the minute it doesnt seem to be working

Last edited by Franklin52; 09-25-2012 at 10:31 AM.. Reason: Please use code tags for data and code samples
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