Formatting File Using Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting File Using Shell Script
# 8  
Old 08-09-2012
No it does not support -r option.

---------- Post updated at 08:19 AM ---------- Previous update was at 06:41 AM ----------

Any others options..available..

---------- Post updated at 10:25 AM ---------- Previous update was at 08:19 AM ----------

Hi Team,

I am able to achieve my objective there is one problem which is coming now.

I am not able to maintain my variables value outside my loop.

Can you help me in it.
# 9  
Old 08-09-2012
Your loop is probably behind a pipe, which puts it in an independent subshell.

Probably, anyway. I can't actually see your computer from here, so please post your code.
# 10  
Old 08-09-2012
My code is as below.
Code:
#!/bin/sh
# Script: EFT.sh
# Purpose: Formatting file to be processed by bank
# Revision History :
#
# Name             Date        Change
# ---------------- ----------- --------------------------------------------------
# Ajay Taneja      07-Aug-2012 Initial Version

#for accepting 549as input
INCHAR="$1"

#for readiing file
INPUT="$2"

#file for processing
OUTPUT1="$3"

#file2 for processing
OUTPUT2="$4"

#for fetching character after first 549 chars
tail +$1c $2 >$3

#for formatting data 100 char per line
fold -100 $3 > $4
echo "Line formatted"

cat /dev/null>>$3
echo "File emptied"
count=1
export count
echo "About to enter while"
while read line 
do 
        echo "Line no is $count"
        xx=`echo "$line" |cut -c65-70`
        if test "$xx" = "CONTRA"
        then
                echo $xx
                break
        fi

        count=`expr $count + 1`
done<$4

#getting the exact data
echo $count
#head -$count $4>$3
echo "Job done"

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 08-09-2012 at 12:43 PM..
# 11  
Old 08-09-2012
Does your sed offer extended regex, maybe not through -r but another option char? Pls check the man page again. What be your sed version?
I'd like to propose an awk solution, but AFA my awk version is concerned, there is no repeat factor like .{n} or .{n,m} available.
# 12  
Old 08-09-2012
My Sed does not offer -r option and even it does not have extended regex command.

Any ways my objective is achieved can you help me with variables value outside a loop.
# 13  
Old 08-09-2012
Odd, I don't see anything that'd prevent variables in the loop from being seen outside it there.

In precisely what way is it misbehaving?
# 14  
Old 08-09-2012
OK, which variable is losing its value outside your loop? I see $count and $xx being used and modified inside the loop, and $count, $3, and $4 used afterwards.

Aside, grep with option -n (for line no.)
Code:
grep -En "^.{66}CONTRA" infile
9:  5555555555555555555555555555555    5555555555555555 44444445 555CONTRA...

will give you the line no. (9) incorporating CONTRA.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need some help in formatting answer of shell script

Dear all, I am new to shell scripting and have tried to make a small program for fun sake that tells age from the last number of cell phone and birth year. At the end we get a final 3 digit number and the first digit represents the last digit of cell phone and rest 2 numbers shows age. eg. 423... (4 Replies)
Discussion started by: stg44
4 Replies

2. Shell Programming and Scripting

Formatting a file using shell script

Hi, Please find the below lines of a file B1/OT "GIB10" 837 130308 1351 MONORONOUS DIGI PATH FAULT SUPER B1/OT "GIB10" 520 130418 1537 MONORONOUS DIGI PATH FAULT SUPER B1/XT "GIB10" 762 130421 0653 TV Y-CEIVER ADMIN RXOCF-62 241_OKEBOLE_NEW 1 B1/XT "GIB10" 385 130425 1931 TV Y-CEIVER... (2 Replies)
Discussion started by: Ardhendu
2 Replies

3. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

4. Shell Programming and Scripting

formatting a shell script

there is one shell which calls for different sql scripts. output of different are formatted in frame like structure.i want columnar wise formatting to be done in such a manner that output of one sql may be comon input of rest sqls . ERC DML Closure Date ER DML SAP Transfer Date ... (0 Replies)
Discussion started by: arc
0 Replies

5. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

6. Shell Programming and Scripting

Formatting a file using shell script

I have a file with contents something similar to as below : SVCNAME,12m-1a,1a-2a,2a-3a,3a-4a,5a-6a,6a-7a,7a-8a,8a-9a,9a-10a,10a-11a,11a-12n,12n-1p,13p-14p,14p-15p,15p-16p,16p-17p,17p-18p,18p-19p,19p-20p,20p-21p,21p-22p,22p-23p,11p-12m, TOTALS... (5 Replies)
Discussion started by: deo_kaustubh
5 Replies

7. Shell Programming and Scripting

Date formatting in shell script

Hi, I am writing a script and I need to calculate last weeks date. I get the current date as; today=`date '+%Y%m%d'` and I need last week inthe same format. Thanks, (2 Replies)
Discussion started by: ozum
2 Replies

8. Shell Programming and Scripting

Formatting the text file using shell script

How to add the filename to end of each line with | as seperator, except first and last line of the file(s) in directories(with diff tree structure) using shell script?. And also how to replace a list of strings with another set of strings, which is present in a file?. Kindly help out on... (1 Reply)
Discussion started by: av_vinay
1 Replies

9. Shell Programming and Scripting

formatting a file using shell script

Hi I have to do the following.I have to format a file test.t The contents are # Header 1231 xyz asdf asdapsdcsd //string1 = "pqrs" //string1 = "abcd"; //info //string1 = "*pqrs"; //add string1 = "#123"; //sub //string1 = "#1234567890" data = check(string1) //string1 = "#1234567890"... (12 Replies)
Discussion started by: gopsman
12 Replies

10. Shell Programming and Scripting

Formatting lines in shell script

I have a file with the below lines 1521 1522 1523 1524 1525 1526 ... 174 lines all numbers like above. I want the above file to appear as below. 1521,1522,1523,1524..... All the numbers should be separated by comma. Pls tell me how to do this .... Thanks in advance. (8 Replies)
Discussion started by: dreams5617
8 Replies
Login or Register to Ask a Question