add line in file and change file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting add line in file and change file name
# 1  
Old 09-07-2012
Bug add line in file and change file name

HI


I have 100 files in below folder:-

/home/lkj/TEST

File name like below
Code:
undo_ARL01003_120907-155022.mos
undo_ARL01006_120908-155042.mos

i want replace one first line of each file to pt all
i want change file name as below.

Code:
ARL01003.mos
ARL01006.mos

Thanks
# 2  
Old 09-07-2012
Hi,
may be this help you:
Quote:
export LIST=`ls`
for file in $LIST; do newname=`echo $file|sed s/oldname/newname/g`; echo "change $file to $newname";mv $file $newname; done;
# 3  
Old 09-07-2012
That's rather a roundabout way of doing it... See Useless Use of Backticks.
Code:
OLDIFS="$IFS"
IFS="-_."

ls | while read A B C D EXT
do
        echo mv "${A}_${B}_${C}-${D}.${EXT}" "${B}.${EXT}"
done

IFS="$OLDIFS"

Remove the echo once you've tested it and are sure it does what you want.
This User Gave Thanks to Corona688 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

How to change file section into each line?

Hi Gurus, I have below file which has different sections, need to move the sections to beginning of the each record. original file aaa bbb ccc ddd eee fff output file. aaa bbb ccc ddd eee fff (6 Replies)
Discussion started by: green_k
6 Replies

2. UNIX for Beginners Questions & Answers

How to change name of the file with first line of the file which has some unwanted text in it?

I have a log file, which i have divided into 14 files using csplit, the file looks like below test-000000 test-000001 #and so on until 14 now I want all the 14 files generated to be renamed as the some part of test in first line of the file how can i eliminate the unwanted text? sample... (5 Replies)
Discussion started by: Sekhar419
5 Replies

3. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

4. Shell Programming and Scripting

Need script to change a line in file....

Hello all, I have a line of code in a file that I need to change in the /etc/sysconfig/kdump file presently the line reads: KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off" what I need to do is put a comment out the 1st line and repeat it, and... (5 Replies)
Discussion started by: gartie
5 Replies

5. Shell Programming and Scripting

create txt file form data file and add some line on it

Hi Guys, I have file A.txt File A Data AK1521 AK2536 AK3164 I want create text file of all data above and write some data on each file. want Output on below folder /home/kka/out AK1521.txt Hi Welocme (3 Replies)
Discussion started by: asavaliya
3 Replies

6. Shell Programming and Scripting

Change in last line of each part of a file

Hi, I have a input files as below. Sample of one input file type mtg_key = record decimal("\344") id; string("\344") ct_cd; string("\344") st_cd; end; type psl_key = record decimal("\344") id; utf8 string("\344") st_cd; end; type amk_fields = record ... (6 Replies)
Discussion started by: adgangwar
6 Replies

7. Shell Programming and Scripting

Modify a file by another file: add new line and variable after string is found

hello, I have problem with writing/adjusting a shell script. I searched forum and unfortunately couldn't write scipt based on the information I found. I never wtire such so it's hard for me and I do need to modify one script immediately. case looks like: 1. 'file' that needs to be modified... (3 Replies)
Discussion started by: bipbip
3 Replies

8. Shell Programming and Scripting

how to change one line in a file?

Suppose I have a file. The content of the file is: Fwf33 #enable_a STH. fwqfw egvega What I want to do is: if "STH" = "YES", do not change it, otherwise, change it to "YES". e.g. if “enable_a ERR” change it to be “enable_a YES” if “enable_a YES” do not change the file. ... (2 Replies)
Discussion started by: lilili07
2 Replies

9. Shell Programming and Scripting

Script to change file contents line by line

Hi, I'm struggling to write a script to do the following, -will go through each line in the file -in a specific character positions, changes the value to a new value -These character positions are fixed througout the file ----------------------- e.g.: file1.sh will have the following 3... (4 Replies)
Discussion started by: vini99
4 Replies

10. UNIX for Dummies Questions & Answers

Change Specific Line of a File

Hi everyone, I am attempting to do something that should be very simple. How do I replace a specific line of a file with different text, and then save that file to its original name? I believe I want to use the sed command with the c option, but I after trying many times, I can't get the right... (10 Replies)
Discussion started by: msb65
10 Replies
Login or Register to Ask a Question