File content modification


 
Thread Tools Search this Thread
Top Forums Programming File content modification
# 1  
Old 02-21-2012
Question File content modification

HI All,

I have a file with content as below
Filename:
my name is xyz
my name abc
my name is bdf
end
Filename:
my name uvx
my name edd
my name jhn
end
i want to edit the content and save into another file as
Filename1:
my name is xyz
Filename1:
my name abc
Filename1:
my name is bdf
Filename2:
my name uvx
Filename2:
my name edd
Filename2:
my name jhn

Please help me in finding the solution.
Regards,
Jhon.
# 2  
Old 02-21-2012
awk

Hi,

Try this one,

Code:
awk 'BEGIN{c=1;}$0 !~ /Filename/{if( $0 ~ /end/ ){c++;}else{print "Filename"c":\n"$0;}}' Input_File_Name

Cheers,
RangaSmilie
# 3  
Old 02-21-2012
Hi Ranga,

I need the solution in C language, sorry for not mentioning it.

Regards,
Jhon.
# 4  
Old 02-21-2012
just use the same logic in C language if you know awk.

Cheers,
RangaSmilie
# 5  
Old 02-21-2012
Hi Ranga,

I don't know how exactly awk work.
Help me find the solution in c.

Regards,
Jhon.
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 remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

2. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 Replies

3. Shell Programming and Scripting

Help For File modification

Hi, I have a file. File contains are as follows : Feb 19, 2012 5:05:00 PM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on http-8080 Feb 19, 2012 5:05:00 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 771 ms Feb 20, 2012... (3 Replies)
Discussion started by: mnmonu
3 Replies

4. Shell Programming and Scripting

File Modification

Hi, I have a file input.txt. cat input.txt output is as follows : Code: "0001"~"name"~"bb"~"20.25"~""~""~"0002"~"name" "dd"~"35.50"~"" ~""~"0003"~"name"~"aa"~"21.3 5"~""~""~ I want the output looking like: cat output.txt Code: "0001"~"name"~"bb"~"20.25"~""~""~... (6 Replies)
Discussion started by: mnmonu
6 Replies

5. Shell Programming and Scripting

Help for File Modification

Hi All, I have a file. This file contain huge amount of data. I want to modify this file. I want enter new line when count of "~ character is 79. Please find below the code : cat file_name | tr -d '\n' | sed... (6 Replies)
Discussion started by: mnmonu
6 Replies

6. Shell Programming and Scripting

Help for File Modification

Hi All, I have a file disk_space.log. cat disk_space.log 94% / 32% /boot 38% /mnt/data 100% /media/CDROM I want the output, like cat disk_space.log 94% / 100% /media/CDROM That means print the line those are grater-than 90%. And rest of the line is remove from file. I have a... (2 Replies)
Discussion started by: mnmonu
2 Replies

7. Shell Programming and Scripting

Help for File Modification

Hi, I have a file abcd.txt. cat abcd.txt output is as follows : "aa"~"bb"~"001"~""~""~"cc" "dd"~"005"~"" ~""~"kk"~"aa"~"00 8"~""~""~ I want the output looking like: cat abcd.txt "aa"~"bb"~"001"~""~""~ "cc""dd"~"005"~""~""~ "kk"~"aa"~"008"~""~""~ I have a script. (4 Replies)
Discussion started by: mnmonu
4 Replies

8. Shell Programming and Scripting

Help with file modification

Hi, I have a file test.txt . The contain of the file is as below : 365798~SAPUS~PR5~0000799005~ADM CHARG MEDCAL INS~~~~~~~~~~~~~~~~~~~~~~~~SLAC480 I want to modify this file. And file contain loking like "365798"~"SAPUS"~"PR5"~"0000799005"~"ADM CHARG MEDCAL... (6 Replies)
Discussion started by: mnmonu
6 Replies

9. UNIX for Dummies Questions & Answers

How to change the file modification time of a file on nfs mount point

Hi I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file. So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)
Discussion started by: deepthi.s
6 Replies

10. Shell Programming and Scripting

File modification

Dear all, i have a file which contains this lines. 0-0 CC=1 0-01 0-011 0-0111 0-01110 F=500 CC=1 L=15 M=5 TRD=3948... (2 Replies)
Discussion started by: panknil
2 Replies
Login or Register to Ask a Question