Help for reformatting text file and creating new format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help for reformatting text file and creating new format
# 1  
Old 07-06-2011
Help for reformatting text file and creating new format

Hi all,

I have an input file like
Code:
1,date,company,,
1,date,comapny,,
2,000,,,567,ACT,00,,,,KKG,M1,D45,,67J,+4500000000
2,000,,,567,ACT,00,,,,KKG,M6,D49,,56J,+6000
2,000,,,567,ACT,00,,7,,KKG,M3,D58,,68h,-70000
2,000,,,567,ACT,00,,,,KKG,M9,D95,,34m,0.00
3,total

what i require is
1.I should add the last column starting with 2 to get the total credit and debit

the above question is solved am able to do that, but i wan to do it after going inside a script not in command line
2.then i would like to pick the last 10 columns of the lines starting with 2 and create a new file format like this
FYI - i will discard rest of the columns am interested only in last 10 columns

new required format

i would want to add X to first and last column in new format and if there is no value in source file then the new file will have just spaces(constant)...

The source files will be around 1500-2000 lines ...can you some one suggest me to write a script in awk,i do know shell scripting but, i was told awk is the best solution for this,am trying my best, would be happy if someone gives me some hints
Code:
X67J  D45M1KKG         X
X56J  D45M1KKG         X
X68h  D45M1KKG    7   X
X34m D45M1KKG         X

answer for first question
1.
Code:
credit_sum=`awk '{ value=substr($0, position, 12); if(value>0) {credit+=value}} END {print credit}' filename` 

debit_sum=`awk '{ value=substr($0, 74, 14); if(value<0) {debit+=value}} END {print debit}' filename`

2. ????

Last edited by Franklin52; 07-06-2011 at 04:05 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-06-2011
can you simply state your problem with some input file format and output file format.

---------- Post updated at 09:48 AM ---------- Previous update was at 09:20 AM ----------

Code:
 
lineno=`wc -l < inputfile`; nawk -F"," -v lineno="$lineno" '{ if (NR> lineno-10) {printf ("X%s %s%s%s %s X\n",$15,$13,$12,$11,$9)}}' inputfile

# 3  
Old 07-06-2011
Ok fine ..i figured out a bit ...

here is the code
cat $INP_FILE1 | while read line
do
echo "$line" | nawk ' BEGIN {FS=","} {print("5",$1,$28,"$27",$26)}' >> $OUT_FILE1
done

But my question now is i want the above action to be performed only when the first column of the input file is having value 3 ..like when line starts with 2 or 1 it should skip those lines

Example of my input file :
1,12,,2099,IF_TB001, 1
2,12,,2099,, 2
3,,103900002,100,110,103900002.116510.,,,,,EUR,,,,,,,47353.17,,,,CT_ACCT,,,,0000000000,JDE,0.00, 3 3,,103900003,100,110,103900003.116510.,,,,,EUR,,,,,,,11457.13,,,,,,,,0000000000,JDE,0.00, 4


Output

0201107051728Corinthian FMCFS CTRON_GL 000188000000000098614.02-00 0000000098614.02+ 140 X
520110614088A20705K USD 0000000008177.41+14088A2000705K0000000000000000000000 X
520110614088471705K USD 0000000000225.00+1408847100705K0000000000000000000000 X
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in creating a file in required format form another existing file

I have a text file with contents like this: a,b,c, d~e,f,g,h~i,j ,k,l,m~n,o,p,q~ I need to convert this file into this format unix shell script commands: a,b,c,d~ e,f,g,h~ i,j,k,l,m~ n,o,p,q~ as you may have noticed, I need to retain the ~ signs at the end. Any help is greatly... (3 Replies)
Discussion started by: harsha1238
3 Replies

2. Shell Programming and Scripting

crontab not creating text file

while running the following code in ssh crontab, Its running successfully but its not creating text file IFC1.txt, file1.txt, file2.txt while running manually its working. please help me #!/bin/ksh hostname > file1.txt 2>/dev/null hostname >> file1.txt 2>/dev/null sudo df -h | grep... (2 Replies)
Discussion started by: elango963
2 Replies

3. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

4. Shell Programming and Scripting

Help in creating a text file

Hi, I need help in creating a file in specific format. I have following lines in a file 0772 0ECC 0FC8 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 (6 Replies)
Discussion started by: jpkumar10
6 Replies

5. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

6. UNIX for Dummies Questions & Answers

creating text file with content from script

hi, can somebody tell me how I can create a text file with content from Bash script. The file should be prefilled with information such as current date and time then leaving the user ability to input more data right below those prefilled content. thank you :) (0 Replies)
Discussion started by: s3270226
0 Replies

7. Shell Programming and Scripting

Help with creating a text file in perl with file creation date.

Hi, I am quite new to Perl scripting and i need to create a .TXT file using perl, with fields (A,B,C,D,E), and this text file should be named with current file creation date "XYZ_CCYYMMDD.TXT" (i.e.XYZ_2011042514:33 PM). Can anyone who has done this, please share their expertise on this... (5 Replies)
Discussion started by: msrahman
5 Replies

8. Homework & Coursework Questions

creating search script for a text file

I am aware of the stipulations regarding homework, however I am completely stuck and do not know how to even begin the following (in bash): Create a script that searches for a text file with most occurrences of a given keyword. Any help is greatly appreciated. Thank you (1 Reply)
Discussion started by: hybridoutlaw
1 Replies

9. Shell Programming and Scripting

Creating a text file in Local Drive

Hi All, I am new in Shell Script. I have a ksh script running in the Unix Server and basically in that script I need to create a text file but the text file has to be generated in the local PC (the user computer such as in C:\ drive). I have no idea on how to do it and I need it pretty urgently.... (2 Replies)
Discussion started by: yramli
2 Replies

10. UNIX for Dummies Questions & Answers

Creating a file in variable length format

Hi all, Does anyone know a technique for creating a download file in variable length format? I have looked around but haven't found any resources on this (or, maybe I'm not sure what to Google for :) ) Thanks in advance! (2 Replies)
Discussion started by: Sarahb29
2 Replies
Login or Register to Ask a Question