replacing in many files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers replacing in many files
# 1  
Old 12-17-2011
replacing in many files

i have 12 files.in all the files the first line will be like:
Code:
H|20111213 09:23:00|267628|617

I need to replace that with current date:
Code:
H|20111217 09:23:00|267628|617

Like this i need to do it for all the files.

One way i can think is inside a loop, use the below code
Code:
a=`sed -n  '1p'|cut -d'|' -f2|cut -c1-8`
b=`date +%Y%m%d`
head -1 file|sed 's/$a/$b/' > file.changed

Is there any other way to achieve this?

Thanks
# 2  
Old 12-17-2011
Assuming ALL your 12 files begin the same, this would work:
Code:
sed -i "1s/H|......../H|$(date +%Y%m%d)/" FILES*

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing extension of files

hi, i am having a certain files in a folder where i need to replace the extension with similar file name for eg 1.csv 2.csv 3.csv 4.csv i need to replace the extension 1.csv 1.txt 2.csv 2.txt 3.csv 3.txt (3 Replies)
Discussion started by: rohit_shinez
3 Replies

2. Shell Programming and Scripting

Replacing strings in various files

i'm trying to figure out the easiest way to replace a string: pineapple pineapple-reg basketball basketball-reg football foot-reg-ball i'm storing the above in a file called wordstoreplace.txt for each line above, the word in the first column is to be replaced by the word in the second... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Parsing all the files in the directory and replacing them

Hi, I would like to parse all the files (*.c and *.h) in the sub-directories and if *.c or *.h files are found I would like to append a string and place it in the same directory. How do I do that? For example: I'm gonna operate on dir1 level. $dir1/subdir1/test.h should be done as... (1 Reply)
Discussion started by: suryaemlinux
1 Replies

4. Shell Programming and Scripting

Replacing variable is files in same directory

Hi all, I'm writing a script to get values from the user and replace it in another file in the same directory. /usr/bin/sediff 's/$PROJECT/'$PROJECT'/' /ananth/TEMPLATE TEMPLATE is the file I want to replace the variable PROJECT from the script I'm writing but Im not getting it done. Is... (4 Replies)
Discussion started by: Ananthdoss
4 Replies

5. Shell Programming and Scripting

Mapping and replacing numbers in two files

hi i have two files one of the form 1 2 2 45 3 56 4 98 5 6598 6 98 7 10 8 0 9 15 10 56 This file's significance is that it maps the number in first column to that of the number in second column The other file is of the form 1 2 (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

6. Shell Programming and Scripting

Replacing the existing files only

Hey, Can someone pls give me an idea on how to write a shell script for the below requirement. I am generating lot of .txt files in a unix directory through a etl tool, now I need to write a shell script which will move these files to another directory(\abc\xyz\source), but in the... (2 Replies)
Discussion started by: shruthidwh
2 Replies

7. Shell Programming and Scripting

Comparing two files and replacing fields

I have two files with ids and email addresses. File 2 cotains a subset of the records in file 1. The key field is the first field containing the id. file 1: 123|myadr@abc.com 456|myadr2@abc.com 789|myadr3@abc.com file 2: 456|adr456@xyz.com Where the record appears in the second... (3 Replies)
Discussion started by: tltroy
3 Replies

8. Shell Programming and Scripting

Replacing string in multiple files

Hi, I need to replace the string 'abcd' with 'xyz' in a file sample.xml This sample.xml is also present in the subdirectories of the current directory. Eg, If I am in /user/home/ the sample.xml if present in /user/home/ /user/home/folder1/ /user/home/folder2/... (3 Replies)
Discussion started by: arulanandsp
3 Replies

9. Shell Programming and Scripting

Replacing string in files

Hi, I Have 10 files ,I need replace $INPUT_LOCATION with $INPUT_LOCATION_upd .using sed command do it single file .How can change all files in single shot instead of doing individual file sed -s'/old/new/g' file1 Thanks, Mohan (2 Replies)
Discussion started by: mohan705
2 Replies

10. Shell Programming and Scripting

replacing tabs to spaces from files

hi, I have some 50 C files in which for indentation of code some devlopers used tabs, but we dont want any tab used for indentation. I have following 2 need. 1) find tabs from all 50 files (which are in one directory ) 2) replace them with 4 spaces. Thanks Rishi (6 Replies)
Discussion started by: rishir
6 Replies
Login or Register to Ask a Question