Hello - Here is my situation. I have a tar file and when I extracted it, I got some N number of text files.
This is how it looks after I extracted from the tar file.
latinum_20080101_0305-200272-93930-2-25.txt
latinum_20080101_0310-200279-93934-2-25.txt
latinum_20080101_0315-200671-94112-2-25.txtand I want to rename them to get the following:
latinum_20080101_0305.txt
latinum_20080101_0310.txt
latinum_20080101_0315.txtThanks
Aarthi
Using "-" as a delimiter, parse the filename looking for the first field. Change the cp to mv once you are satisfied this works: #!/bin/bash for file in latinum*.txt do set -- $(IFS="-"; echo $file) cp "$file" "${1}.txt" done
Many thanks for your response. I have made a mistake. the file name structure is like this: latinum.8300.ram_ips-200272.txt
uranmium.0305.ram_ips-200286.txt
platinum.1800.ram_ips-200256.txt
and I want to rename them to get the following:latinum.8300.ram_ips.txt
uranium.0305.ram_ips.txt
platinum.1800.ram_ips.txtis there any single line command(awk, sed) instead writing a shell script?
Thanks
Aarthi
The only thing that changes is the pattern: for file in latinum*.txt
to:
for file in *ram_ips.txt
You might be able to do it with an awk script, but I wouldn't consider it a "one-liner". After parsing the file name, you would have to build a string and use awk's system command to call the external move command. It's not something I want to do.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |