how to shift few words of filenames at a time using shell script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to shift few words of filenames at a time using shell script
# 1  
Old 07-09-2010
MySQL how to shift few words of filenames at a time using shell script

Hello everybody,

I have some files in directory. I want to shift 3 characters of filenames to the right at a same time.

for example, I have filenames like $ls -l

I want to change the filenames like

Thins means I want to shift first 3 characters to the 8th position and I want to replace .G3. to _MFM_ also.

Any suggestions are welcome.
# 2  
Old 07-10-2010
using bash:
for f in *input.txt; do echo "${f:3:4}_${f::3}MFM_${f: -9}"; done

# 3  
Old 07-10-2010
but filenames not getting changed.

Thanks for the reply.

This works fine. I could only see the changed filenames in a prompt mode.
Actual filenames are not changed.

I think I have to add something like >&

Please suggest. and if possible explain few steps. particularly about {f:3:4} and {f: -9}
# 4  
Old 07-10-2010
I don't know what you want to do, so I just showed how to transform your filenames. You have to use cp or mv.

it's ${var:begin:length}, where begin is the beginning position, length is the number of characters.
you can read more about Parameter Expansion in the bash's manpage.
This User Gave Thanks to daPeach For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stemming of words that contained affixes by using shell script

I just learning shell script. Need your shell script expertise to help me. I would like to stemming the words by matching the root words first between both files and replace all words by "I" character but replace "B" character after root words and "E" before root words in affix_words.txt. ... (18 Replies)
Discussion started by: paranrat
18 Replies

2. UNIX for Advanced & Expert Users

Shell script to convert words to Title case

Hi :) I have a .txt file with thousands of words. I was wondering if i could use a simple sed or awk command to convert / replace all words in the text file to Title Case format ? Example: from: this is line one this is line two this is line three to desired output: This Is Line... (8 Replies)
Discussion started by: martinsmith
8 Replies

3. Shell Programming and Scripting

Shell script to read words into an array

Hello, I have output like below: ----------------------------------------------------------------------------- Group 'group1' on system 'system01' is running. ----------------------------------------------------------------------------- Group 'group2' on system 'system01' is running.... (4 Replies)
Discussion started by: sniper57
4 Replies

4. Shell Programming and Scripting

Storing filenames in an array in shell script

hi, i am writing a shell script in which i read a line in a variable. FNAME="s1.txt s2.txt s3.txt s4.txt s5.txt" i want to create a array and store single file names in a array.. so the array should contain arr="s1.txt" arr="s2.txt" arr="s3.txt" arr="s4.txt" arr="s5.txt" how to... (3 Replies)
Discussion started by: Little
3 Replies

5. Shell Programming and Scripting

shell script: cannot shift error?

This is an assignment where we were supposed to create a script to get an orginal string and replace it with another. However when I run my script (change-lines), it says ./change-lines: cannot shift I do not where the problem is. help! #!/bin/sh # a shell function to print and error... (4 Replies)
Discussion started by: alis
4 Replies

6. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

7. Shell Programming and Scripting

shell script to print words having first and last character same.

Hi I want to write a shell script to print only those words from a file whose beginning and last character are same. Please help. Thanks, vini (5 Replies)
Discussion started by: vini kumar
5 Replies

8. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

9. Shell Programming and Scripting

Need to change two words in a line using shell script.

Hi, i have a line tftp dgram udp wait nobody /usr/sbin/tcpd in.tftpd /tftpboott in /etc/inet.conf file. ineed to replace nobody with root and /tftpboott with /flx/boot. i tried using sed ,but i could not change both of them. can you please help me to do this. Edit:... (7 Replies)
Discussion started by: vprasads
7 Replies

10. Shell Programming and Scripting

How to list filenames with spaces in shell script

Hi, I want to list all the files matching in a directory directory given below Here one of the folder has a space in the path. /MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0 The following works from command line... (1 Reply)
Discussion started by: hikrishn
1 Replies
Login or Register to Ask a Question

Featured Tech Videos