Sponsored Content
Top Forums Shell Programming and Scripting Help for reformatting text file and creating new format Post 302536582 by selvankj on Tuesday 5th of July 2011 11:40:22 PM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 01:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy