Sponsored Content
Top Forums Shell Programming and Scripting Shell script to read a text file line by line & process it... Post 302554767 by new_to_shell on Tuesday 13th of September 2011 03:24:47 AM
Old 09-13-2011
Hi,

Can you please help me to check the format of a number in a file

ex: that each entry is only 5 digits & numeric only, no alphabets, & its not empty.ex: 34150

it should also give message if the format is wrong

I used :

if ! echo "$line" | grep '[0-9]\{5\}$' >/dev/null 2>&1 ; then
error_msg "AVL format is invalid" >> ${LOG_FILE}
exit 1
fi
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

shell script to process file line by line

Hi , I am new to shell scripting (ksh shell) and trying to accomplish few requiremtns. I have a file with the following format EMP NO EMP NAME AGE Amt Paid 12 Mark Taylor 32 32333 14 James Brown... (5 Replies)
Discussion started by: royalsing
5 Replies

2. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

3. UNIX for Dummies Questions & Answers

shell script to read file line by line

Hi, I need to read a text file from shell script line by line and copy the feilds of each line. Below is the complete requirement. I've text file which contains ... pgm1 file11 file12 file13 pgm2 file21 file22 pgm3 file31 file32 file33 I'll give input as... (4 Replies)
Discussion started by: ani12345
4 Replies

4. Shell Programming and Scripting

how can u read a file line by line in shell script ?

hello , plz help for below script req:- how can we read a file line by line in shell script ? (4 Replies)
Discussion started by: abhigrkist
4 Replies

5. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

6. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

7. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

8. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

9. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

10. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies
MONEY_FORMAT(3) 							 1							   MONEY_FORMAT(3)

money_format - Formats a number as a currency string

SYNOPSIS
string money_format (string $format, float $number) DESCRIPTION
money_format(3) returns a formatted version of $number. This function wraps the C library function strfmon(3), with the difference that this implementation converts only one number at a time. PARAMETERS
o $format - The format specification consists of the following sequence: oa % character ooptional flags ooptional field width ooptional left precision ooptional right precision oa required conversion character Flags One or more of the optional flags below can be used: o = f - The character = followed by a (single byte) character f to be used as the numeric fill character. The default fill character is space. o ^ - Disable the use of grouping characters (as defined by the current locale). o + or ( - Specify the formatting style for positive and negative numbers. If + is used, the locale's equivalent for + and - will be used. If ( is used, negative amounts are enclosed in parenthesis. If no specification is given, the default is +. o ! - Suppress the currency symbol from the output string. o - - If present, it will make all fields left-justified (padded to the right), as opposed to the default which is for the fields to be right-justified (padded to the left). Field width o w - A decimal digit string specifying a minimum field width. Field will be right-justified unless the flag - is used. Default value is 0 (zero). Left precision o # n - The maximum number of digits ( n) expected to the left of the decimal character (e.g. the decimal point). It is used usually to keep formatted output aligned in the same columns, using the fill character if the number of dig- its is less than n. If the number of actual digits is bigger than n, then this specification is ignored. If group- ing has not been suppressed using the ^ flag, grouping separators will be inserted before the fill characters (if any) are added. Grouping separators will not be applied to fill characters, even if the fill character is a digit. To ensure alignment, any characters appearing before or after the number in the formatted output such as currency or sign symbols are padded as necessary with space characters to make their positive and negative formats an equal length. Right precision o . p - A period followed by the number of digits ( p) after the decimal character. If the value of p is 0 (zero), the decimal character and the digits to its right will be omitted. If no right precision is included, the default will dictated by the current local in use. The amount being formatted is rounded to the specified number of digits prior to formatting. Conversion characters o i - The number is formatted according to the locale's international currency format (e.g. for the USA locale: USD 1,234.56). o n - The number is formatted according to the locale's national currency format (e.g. for the de_DE locale: EU1.234,56). o % - Returns the % character. o $number - The number to be formatted. RETURN VALUES
Returns the formatted string. Characters before and after the formatting string will be returned unchanged. Non-numeric $number causes returning NULL and emitting E_WARNING. NOTES
Note The function money_format(3) is only defined if the system has strfmon capabilities. For example, Windows does not, so money_for- mat(3) is undefined in Windows. Note The LC_MONETARY category of the locale settings, affects the behavior of this function. Use setlocale(3) to set to the appropriate default locale before using this function. EXAMPLES
Example #1 money_format(3) Example We will use different locales and format specifications to illustrate the use of this function. <?php $number = 1234.56; // let's print the international format for the en_US locale setlocale(LC_MONETARY, 'en_US'); echo money_format('%i', $number) . " "; // USD 1,234.56 // Italian national format with 2 decimals` setlocale(LC_MONETARY, 'it_IT'); echo money_format('%.2n', $number) . " "; // Eu 1.234,56 // Using a negative number $number = -1234.5672; // US national format, using () for negative numbers // and 10 digits for left precision setlocale(LC_MONETARY, 'en_US'); echo money_format('%(#10n', $number) . " "; // ($ 1,234.57) // Similar format as above, adding the use of 2 digits of right // precision and '*' as a fill character echo money_format('%=*(#10.2n', $number) . " "; // ($********1,234.57) // Let's justify to the left, with 14 positions of width, 8 digits of // left precision, 2 of right precision, withouth grouping character // and using the international format for the de_DE locale. setlocale(LC_MONETARY, 'de_DE'); echo money_format('%=*^-14#8.2i', 1234.56) . " "; // Eu 1234,56**** // Let's add some blurb before and after the conversion specification setlocale(LC_MONETARY, 'en_GB'); $fmt = 'The final value is %i (after a 10%% discount)'; echo money_format($fmt, 1234.56) . " "; // The final value is GBP 1,234.56 (after a 10% discount) ?> SEE ALSO
setlocale(3), sscanf(3), sprintf(3), printf(3), number_format(3). PHP Documentation Group MONEY_FORMAT(3)
All times are GMT -4. The time now is 08:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy