Edit file contents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edit file contents
# 1  
Old 02-23-2010
Edit file contents

I have a file with a list of dates(calendar) business1-christmaseve and this needs to be edited as follows, so I get business2-christmaseve with 2 extra lines in it - one is the file name and the second is an "a".

from
Code:
[ server ]cat business1-christmaseve
12/24/2009 00:00
12/24/2010 00:00
12/24/2011 00:00
12/24/2012 00:00

to
Code:
[ server ]cat business2-christmaseve
business2-christmaseve
a
12/24/2009 00:00
12/24/2010 00:00
12/24/2011 00:00
12/24/2012 00:00

Thanks.
Stephan

Last edited by Scott; 02-23-2010 at 04:57 PM.. Reason: Code tags please...
Stephanica
# 2  
Old 02-23-2010
Quote:
Originally Posted by Stephanica
I have a file with a list of dates(calendar) business1-christmaseve and this needs to be edited as follows, so I get business2-christmaseve with 2 extra lines in it - one is the file name and the second is an "a".

from
[ server ]cat business1-christmaseve
12/24/2009 00:00
12/24/2010 00:00
12/24/2011 00:00
12/24/2012 00:00

to
[ server ]cat business2-christmaseve
business2-christmaseve
a
12/24/2009 00:00
12/24/2010 00:00
12/24/2011 00:00
12/24/2012 00:00

Thanks.
Stephan
Code:
cp business1-christmaseve business2-christmaseve
sed -i '1ia' business2-christmaseve
sed -i '1ibusiness2-christmaseve' business2-christmaseve


Last edited by Scott; 02-23-2010 at 04:57 PM.. Reason: Code tags please...
# 3  
Old 02-23-2010
Thank you, 3junior.
Sorry I forgot to mention the -i option will not work on Solaris 10
sed: illegal option -- i
Suggestions?
Stephanica
# 4  
Old 02-23-2010
Tools By brute force?

Code:
echo 'biz2-christmas' >biz2.txt ; echo 'a' >>biz2.txt ; cat biz.txt >>biz2.txt

# 5  
Old 02-23-2010
Code:
{ printf 'business2-christmaseve\na\n'; cat business1-christmaseve; } > business2-christmaseve

# 6  
Old 02-23-2010
Code:
exec > business2-christmaseve
echo business2-christmaseve
echo a
cat business1-christmaseve

# 7  
Old 02-24-2010
Thanks, guys. These solutions work for each file.
Can we get to make this run for a list of files like the one in the example?

#index file contains the list of calendars to be renamed and edited.
cat index
business1-christmas
business1-holidays
business1-independenceday
business1-labourday
business1-memorialday
business1-newyearsday
business1-presidentsday

Thanks for all responses.
Stephanica
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

3. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

4. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

5. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

6. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

7. Shell Programming and Scripting

Edit value in File

I have a file oratab with entry like this SCADAG:/esitst1/oracle/product/9.2.0.8:Y I am trying to discover a way to change the 9.2.0.8 part of this to something like 10.2.0.4 as part of an upgrade script. I have tried cat /etc/oratab >>/tmp/oratab... (1 Reply)
Discussion started by: sewood
1 Replies

8. Shell Programming and Scripting

file edit help

Hi, Could anyone give me a idea how to strip the lines from a given file. example *********** 1st occurence 1st occurence 1st occurence 1st occurence *********** 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence 2nd occurence ************* 3rd occurence 3rd... (10 Replies)
Discussion started by: sentak
10 Replies

9. Shell Programming and Scripting

Creating file contents using contents of another file

Hi, I am not sure how to start doing this so I hope to get some advice as to how to start. I have 2 files. The source file contains data that I needed is in columns delimited by ";". For example, in this format: "CONTINENT","COUNTRY","CITY","ID" "asia","japan","tokyo","123"... (21 Replies)
Discussion started by: ReV
21 Replies

10. UNIX for Dummies Questions & Answers

file name edit

ok I have a list of files for example: 130-4-32.HindIII.0.ids 130-4-32.HindIII.0.ppm 130-4-32.HindIII.0.ppm.gz 130-4-33.HindIII.0.bands 130-4-33.HindIII.0.ics 130-4-33.HindIII.0.ids 130-4-33.HindIII.0.ppm 130-4-33.HindIII.0.ppm.gz 130-4-34.HindIII.0.bands ... (1 Reply)
Discussion started by: lorcet222
1 Replies
Login or Register to Ask a Question