Unfold the data from a input file and write to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unfold the data from a input file and write to a file
# 1  
Old 10-14-2011
Unfold the data from a input file and write to a file

I am working on a script to unfold data for each column from a specific line of data and write output in a single line.

Input data looks like this.

HTML Code:
2011-09-26 INF UM_10 UserMana Starting synchronization for security domain
14:37:31       080   gementSe [12345].
                     rvice
I prepared the script to unfold the above data

HTML Code:
#!/usr/bin/ksh
while read mDate mRest; do
  if [[ ${#mDate} -eq 10 ]]; then
    if [[ "${mOut}" != "" ]]; then
      echo ${mOut}
    fi
    mOut=''
  fi
  mOut=${mOut}' '${mDate}' '${mRest}
done < Inp_File
if [[ "${mOut}" != "" ]]; then
  echo ${mOut}
fi

The problem with this script is it simply cuts the data from 2nd and 3rd lines and attaches to the first line.

HTML Code:
2011-09-26 INF UM_10 UserMana Starting synchronization for security domain 08:45:10 080 gementSe [12345]. rvice
But I want the data to be like this:

HTML Code:
2011-09-26 14:37:31 INF UM_10080 UserManagementService Starting synchronization for security domain [12345].
Thanks,
Bob
# 2  
Old 10-15-2011
Code:
awk '{a=a FS substr($0,1,10);b=b FS substr($0,12,3);c=c FS substr($0,16,5);d=d FS substr($0,22,8);e=e FS substr($0,31)}
    END{gsub(/ *$/,"",a);gsub(/ /,"",b);gsub(/ /,"",c);gsub(/ /,"",d);print a,b,c,d,e}' infile

This User Gave Thanks to rdcwayx For This Post:
# 3  
Old 10-17-2011
Thanks. Let me try and get back to you in case of any issues.

Thanks,
Bob
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

3. 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

4. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

5. Shell Programming and Scripting

Read user input, Encrypt the data and write to file

Hi, can some one help me how to encrypt and decrypt a file. AIM: reade user input, encrypt it and save it to file. while decryption read the encrypted file decrypt it and save the output in some variable. Example: consider we have Credentials.txt file with content username: password... (5 Replies)
Discussion started by: saichand1985
5 Replies

6. Shell Programming and Scripting

Help to write a script or program to automatic execute and link input file data

Output file template format <input_file_name>a</input_file_name> <total_length_size>b</total_length_size> <log_10_length_size>c</log_10_length_size> Input_file_1 (eg. sample.txt) SDFSDGDGSFGRTREREYWW Parameter: a is equal to the input file name b is equal to the total length of... (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. Shell Programming and Scripting

Read the apecific data from one file and write into another file

Hi, I would like to read the specific data from file and write the data in the new file. My data input is something like this.. <EXROP:R=TJ0311T; ROUTE DATA R ROUTE PARAMETERS TJ0311T DETY=UPDR TTRANS=1 FNC=3 MA=628160955000 R=TJ0311D ... (3 Replies)
Discussion started by: bha148
3 Replies

8. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

9. Shell Programming and Scripting

get data from input file and write another file

Hi, i have doubt in read and write using bash shell script... i will give the input file path and output file path in command line ex : example.sh iputfile outpilepath Here i need to read the input data then write that data to output file.. please give some example : (6 Replies)
Discussion started by: karthinvk
6 Replies

10. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies
Login or Register to Ask a Question