Editting each line in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Editting each line in a file
# 1  
Old 08-30-2010
Editting each line in a file

Hi
Can anyone please help me in resolving my issue.
I have a file with entries like this
t9787ms 99970 22/08/2010 12:30 /www.google.com
t9788ms 99942 22/08/2010 12:40 /www.google.com
t4788ms 88942 22/08/2010 01:40 /www.google.com

there are around 5 lakh records of this type my requirement is to change the file to
<tid>t9787ms</tid> <dlr>99970</dlr> <dat>22/08/2010</dat> <tim>12:30</tim> <url>/www.google.com</url>
all the entries needs to be changed in this way .
# 2  
Old 08-30-2010
give a sample for you, you can finish the rest.

Code:
awk '{print "<tid>",$1,"</tid>", "<dlr>" $2 "</dlr>"  }' infile

# 3  
Old 08-31-2010
yeah this would give the exact format you want:

Code:
awk '{print "<tid>"$1"</tid>", "<dir>"$2"</dir>", "<dat>"$3"</dat>", "<tim>"$4"</tim>", "<url>"$5"</url>"}' infile >infile.new; rm -rf infile; mv infile.new infile

# 4  
Old 08-31-2010
Thanks alot that worked
is there any chance to add <XML> at the start of the file and </XML> at the end . I will be appending these kind of records to the same file daily .
example :
day 1: <XML>
<tid>s99152g</tid> <dir>33420</dir> <date>29/Aug/2010</date> <time>02:46:48</time> <url>/service/claimadmin/quicklop/dcx</url>
<tid>s07560k</tid> <dir>33132</dir> <date>29/Aug/2010</date> <time>03:31:55</time> <url>/service/claima
dmin/quicklop/dcx</url>
</XML>

day 2 :
<tid>s99152g</tid> <dir>33420</dir> <date>29/Aug/2010</date> <time>02:46:48</time> <url>/service/claimadmin/quicklop/dcx</url>
<tid>s07560k</tid> <dir>33132</dir> <date>29/Aug/2010</date> <time>03:31:55</time> <url>/service/claima
dmin/quicklop/dcx</url>
<tid>s07560k</tid> <dir>33132</dir> <date>29/Aug/2010</date> <time>03:44:47</time> <url>/service/claima
dmin/quicklop/dcx</url>
</XML>
new records needs to be added between these <XML> tags is it possible if so please let me know .

Thanks in advance
# 5  
Old 08-31-2010
Code:
awk '
BEGIN{print "<XML>"} 
{print "<tid>",$1,"</tid>", "<dlr>" $2 "</dlr>"  }
END {print "</XML>"} 
' infile

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 read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Editting a record

robert (6 Replies)
Discussion started by: robert89
6 Replies

4. Linux

Problem editting the first occurence of a pattern in the first uncommented line

Hi I have to replace a pattern found in the first uncommented line in a file. The challenge I'm facing is there are several such similar lines but I have to edit only the first uncommented line. Eg: #this is example #/root/xyz:Old_Pattern /root/xyz:Old_Pattern /root/xyz:Old_Pattern ... (10 Replies)
Discussion started by: Stoner008
10 Replies

5. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

6. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

7. UNIX for Dummies Questions & Answers

matching IDs from two files and editting

I have two files. One has: ID# 0 a b c d e f g h i j k....................~2 milion columns ID# 0 l m n o p q r s t u v....................~2 milion columns . . . ~6000 lines Other has: ID# 1 or ID# 2 . . ~6000 lines (2 Replies)
Discussion started by: polly_falconer
2 Replies

8. Shell Programming and Scripting

editting file

Hi, I am having sequence of process ids in one file. My file contents is (Output of fuser someobject.so). 654 14583 17890 25902 This no. of processes may vary depends up on the object. I want to check all the processes one by one. If i want to apply egrep, I need to... (3 Replies)
Discussion started by: sharif
3 Replies

9. Shell Programming and Scripting

Unix file editting commands

ok, are there any other file editting commands out there other than the below that comes with sunsolaris & linux vi, emacs, ed, (1 Reply)
Discussion started by: Terrible
1 Replies

10. Shell Programming and Scripting

file editting with shell programmin

Hello, I have several handreds of text files. The format of file looks like: column1 column2 column3 column4 column5 id1 definition1 name1 fieldid comm1 id2 definition2 name2 fieldid ... (4 Replies)
Discussion started by: ssshen
4 Replies
Login or Register to Ask a Question