Change the write in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change the write in file
# 1  
Old 05-24-2016
Change the write in file

Hello

I have a file log with one information in many lines but i want the information log just per line.
How can i do to do this in shell langage.




Input file :
Code:
 Info : [Log] etstst trerer
 tetststsss
 Warning : [Log] informatopnn
 eysysysysys
 rererererer
 Error : [Log] this is an error log  
 with information in many phrases


what I need in output file:


Code:
 Info : [Log] etstst trerer tetststsss
 Warning : [Log] informatopnn eysysysysys
 Error : [Log] this is an error log with information in many phrases



Thanks you in advance
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 05-24-2016 at 04:44 PM.. Reason: Add CODE tags.
# 2  
Old 05-24-2016
1) Please use code tag
2) What have you tried so far ?
# 3  
Old 05-24-2016
Hello RavinderSingh1,

Thanks you very much but Some time we have not the word before the [log]. could you please to do it with only the kew word [Log]

---------- Post updated at 08:55 AM ---------- Previous update was at 06:25 AM ----------

Input file :
Code:
Info : [Log] etstst trerer
tetststsss
Warning : [Log] informatopnn
eysysysysys
rererererer
Error : [Log] this is an error log 
with information in many phrases 
[Log] this is anererer
rerererere

what I need in output file:

Code:
Info : [Log] etstst trerer tetststsss
Warning : [Log] informatopnn eysysysysys
Error : [Log] this is an error log with information in many phrases
[Log] this is anererer rerererere.

I want just to use the keywork [Log] to write all the information from multiple line to one line.

Last edited by Don Cragun; 05-24-2016 at 04:47 PM.. Reason: Add CODE and ICODE tags again.
# 4  
Old 05-24-2016
This one prints/empties the buffer sooner. Saves memory if the log file is big.
Code:
awk '/\[Log\]/ {if (NR>1) print buf; buf=$0; next} {buf=buf FS $0} END {if (NR>1) print buf}' file

With sed
Code:
sed -n '
  :L
  $p; N
  /\n.*\[Log\]/{
    P; D
  }
  s/\n/ /
  bL
' file

# 5  
Old 05-24-2016
Guys, I think when a fellow, established member asks "What have you tried so far" it's courteous to wait for a response from the O/P in such regard before offering possible solutions.

My $0.02.
This User Gave Thanks to Scott For This Post:
# 6  
Old 05-24-2016
Quote:
Originally Posted by Scott
Guys, I think when a fellow, established member asks "What have you tried so far" it's courteous to wait for a response from the O/P in such regard before offering possible solutions.
My $0.02.
Hello Scott,

Greetings !!

Good to see you sir. Yes, even I do agree when a member asks user question we shouldn't reply answers. If you see the time of my and Pravin's post we posted on exact sametime. After that when I tried to delete that post I got an error not sure if it's a browser issue may be, so couldn't delete it.

EDIT: I have deleted my both posts now. Somehow I was not able to do that yesterday.

Thanks,
R. Singh

Last edited by RavinderSingh13; 05-25-2016 at 02:05 AM.. Reason: Added a comment.
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 05-24-2016
Hey, mate, thanks, good to see you too Smilie

It's not an issue, of course, but without knowing where boudake's knowledge is at we can't know at which level to pitch our support. (that seemed to make sense when I wrote it lol)
This User Gave Thanks to Scott 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

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

2. Shell Programming and Scripting

Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file. Kindly provide your input. File is like below Jan 11 04:05:10 linux100 |NOTICE... (2 Replies)
Discussion started by: Raysf
2 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Hardware

Hardware Correction: How to change DVD write speed

I am now on Kernel 2.6.32-26 For me 16x CD write speed is okay. I have old hardware which was able to write DVDs at 1x, back in previous linux version. Now, I dont get speed of less than 4x. Tested on k3b, xfburn, and brasero. But all start at bottom 4x write speed. k3b forced back to... (0 Replies)
Discussion started by: makh
0 Replies

5. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

6. Shell Programming and Scripting

Help required to write shell script to change passwd

Hi All, I wanted to write a shell script which will change the expired passwd in oracle. Here is below what I am trying, #!/bin/sh set -x ORACLE_HOME="/optware/oracle/9.2.0.2_64" SQLPLUS="${ORACLE_HOME}/bin/sqlplus" PASS="xyz" PATH=$ORACLE_HOME/bin:$PATH... (0 Replies)
Discussion started by: gr8_usk
0 Replies

7. Shell Programming and Scripting

how to write script to change email address

we have 4000 html pages that need an email address changed. eg) company@yahoo.com to company@hotmail.com we only want the file modified date to be changed when there has been a change to the file. Should I be using grep? I fairly new to UNIX and was told to using something like... (2 Replies)
Discussion started by: mchelle_99
2 Replies

8. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

9. UNIX for Dummies Questions & Answers

search change write

i="1" while do k=`expr $i + 1` sed -e 's/"$i"/"$k"/' < somefile1.txt >> somefile2.txt i=`expr $i + 1` done ive been trying to : 1 from a file containing numbers in a row divided with correct number of spaces to find the corresponding one 2 change the value 3 and append... (3 Replies)
Discussion started by: trilicno
3 Replies

10. UNIX for Dummies Questions & Answers

search change write

i="1" while do k=`expr $i + 1` sed -e 's/"$i"/"$k"/' < somefile1.txt >> somefile2.txt i=`expr $i + 1` done ive been trying to : 1 from a file containing numbers in a row divided with correct number of 2 spaces to find the corresponding one 2 change the value 3 and append... (1 Reply)
Discussion started by: trilicno
1 Replies
Login or Register to Ask a Question