- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help in scripting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 12:25 AM
тАО06-10-2003 12:25 AM
i need some help on scripting
one of my user has the following requirement, can anybody help?
The text file below will be taken as an input to the shell script and do the following
1)
The length of the bill type field (2nd field)should be checked
If the length = 2 then the bill type should be padded with 2 zero???s to the left.
(E.g. : if bill type = 1, then it should be 0001)
If the length = 1 then the bill type should be padded with 3 zero???s to the left.
(E.g. : if bill type = 19, then it should be 0019)
2)
Pad the date field (5th field)with ???. 000??? (dot space and then 000)
(Eg:2003-04-01 09:29:24. 000)
The date field is the 5th column in the text file.
The text file will be always of the same format.
Attached the input file
Regds
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 12:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 01:27 AM
тАО06-10-2003 01:27 AM
Re: help in scripting
Awk statement that prints the second variable as zero filled to 4 characters.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 01:36 AM
тАО06-10-2003 01:36 AM
Re: help in scripting
cat /tmp/test1 |awk '{var="0000"$2;print $1" "substr(var, length(var)-3, 4)}'
Note the changes, var-3. Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 01:45 AM
тАО06-10-2003 01:45 AM
Re: help in scripting
Check this script.This should meet your both requirement.
cat input |awk -F "~" '{printf("%s~%04d~%s~%s~%s. 000~%s~%s~%s\n",$1, $2 , $3, $4, $5, $6, $7, $8 )} '
OR
cat input |awk -F "~" '{printf("%04d~%s. 000\n", $2, $5)} '
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 01:47 AM
тАО06-10-2003 01:47 AM
Re: help in scripting
You can do both the things like this
cat
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 01:48 AM
тАО06-10-2003 01:48 AM
Re: help in scripting
One approach. Try running the attached script like this:
# attached.sh
Slow, but simple to correct.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 02:05 AM
тАО06-10-2003 02:05 AM
Re: help in scripting
1000132873~0001~01~1270~2003-04-01 09:29:24. 000~ NARASIMHA REDDY B V~HYDERABAD~HYD000
1000388231~0001~01~1736~2003-04-01 09:34:13. 000~ PRAJA SAKTI TELUGU DAILY~HYDERABAD~HYD000
1000427496~0001~01~2300~2003-04-01 09:37:10. 000~ NVS NAIDU~HYDERABAD~HYD000
1000421963~0001~01~1060~2003-04-01 09:38:17. 000~ VVR CHOWDARY~HYDERABAD~HYD000
1000299151~0001~01~1760~2003-04-01 09:38:59. 000~ . AJAY DESHPANDE~HYDERABAD~HYD000
1000214434~0002~01~3570~2003-04-01 09:40:44. 000~ P VENKATA RAMA REDDY~HYDERABAD~HYD000
1000416477~0001~01~1600~2003-04-01 09:43:41. 000~ VARMA BALAVENKATA MANTHENA~VISAKHAPATNAM~FTFVIZ
1000129441~0001~01~250~2003-04-01 09:52:44. 000~ Dr.R.C.MATHUR~HYDERABAD~HYD000
1000109493~0001~01~4974~2003-04-01 09:53:05. 000~ M.RAMAKRISHNA RAJU~VIJAYAWADA~FTFVIJ
1000431318~0001~01~1100~2003-04-01 09:58:08. 000~ LAKSHMI PIRIMITI~VISAKHAPATNAM~FTFVIZ
1000117363~0002~01~1012~2003-04-01 09:58:56. 000~ GUNDRA NAGARAJU~SECUNDERABAD~S11000
1000373683~0002~01~749~2003-04-01 10:02:38. 000~ KAJA VIJAY SEKHAR~SECUNDERABAD~S11000
1000364205~0001~01~2300~2003-04-01 10:04:15. 000~ JAGANNADHA RAO SAKISA~VISAKHAPATNAM~FTFVIZ
1000453189~0001~01~540~2003-04-01 10:05:36. 000~ LAKSHMANA RAO KANTIBOTHU~VISAKHAPATNAM~FTFVIZ
1000162369~0001~01~1300~2003-04-01 10:05:36. 000~ POTLURI RAJ KUMAR~VIJAYAWADA~FTFVIJ
1000125600~0001~01~1765~2003-04-01 10:06:25. 000~ DR.N.SUBBA RAO~VIJAYAWADA~FTFVIJ
1000129590~0004~01~825~2003-04-01 10:08:16. 000~ DR G LAKSHMI~HYDERABAD~HYD000
1000271829~0001~01~1016~2003-04-01 10:09:53. 000~ NV RAMANA REDDY~HYDERABAD~H13000
1000444683~0002~01~1817~2003-04-01 10:12:04. 000~ Y MURALI KRISHNA~HYDERABAD~H13000
1000154221~0001~01~1180~2003-04-01 10:12:06. 000~ G PULLA REDDY~HYDERABAD~HYD000
1000243766~0001~01~1100~2003-04-01 10:12:39. 000~ SAJJA CHANDRA MOHAN~VIJAYAWADA~FTFVIJ
1000434884~0001~01~3230~2003-04-01 10:14:02. 000~ J BABU~VIJAYAWADA~FTFVIJ
1000454701~0001~01~498~2003-04-01 10:14:50. 000~ K HARIHARAN~VIJAYAWADA~FTFVIJ
1000412340~0001~01~4520~2003-04-01 10:16:14. 000~ SN CONSTRUCTIONS~HYDERABAD~HYD000
1000189588~0001~01~975~2003-04-01 10:18:53. 000~ M TULASIDAS~VIJAYAWADA~FTFVIJ
1000277301~0001~01~1107~2003-04-01 10:18:54. 000~ SURESH KUMAR JAIN~VIJAYAWADA~V02000
1000184404~0002~01~920~2003-04-01 10:19:51. 000~ M VISWESWARAIAH -~HYDERABAD~H13000
1000229466~0001~01~900~2003-04-01 10:19:58. 000~ P MUNISHEKAR REDDY~HYDERABAD~HYD120
1000307857~0001~01~974~2003-04-01 10:21:04. 000~ T.D.REDDY GRAPE GARDEN~SECUNDERABAD~S11000
1000117843~0001~01~2576~2003-04-01 10:21:18. 000~ N.VISHNU V REDDY~HYDERABAD~H13000
1000424059~0019~01~1546.5~2003-04-01 10:22:32. 000~VENKATANARASIMHA~HYDERABAD~HYD000
1000229427~0001~01~900~2003-04-01 10:23:49. 000~ NEKKALAPUDI ANJAYYA~VIJAYAWADA~FTFVIJ
1000139194~0001~01~1430~2003-04-01 10:24:43. 000~ J.PAPARAO~VIJAYAWADA~FTFVIJ
1000352619~0001~01~1443~2003-04-01 10:26:45. 000~ N SRIHARI RAO~GUNTUR~GUN050
1000270169~0001~01~2940~2003-04-01 10:26:47. 000~ M SAMBI REDDY~VIJAYAWADA~FTFVIJ
l1:/tmp 109 >
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 02:37 AM
тАО06-10-2003 02:37 AM
Re: help in scripting
thank u all for ur inputs,
i have written a script like this:
echo "Enter the input file name:\c"
read filein
awk -F~ '{var="0000"$2;print $1"~"substr(var,length(var)-3,4)"~"$3"~"$4"~"$5". 000~"$6"~"$7"~"$8}' $filein >$filein.out
echo "\nThe modified output file name is:$filein.out"
Tamil:
do u know me?
Regds
M.Kantharuban /HCL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-10-2003 05:05 AM
тАО06-10-2003 05:05 AM
Re: help in scripting
typeset -Z4 FIELD2
cat your_file | while read FIELD1 FIELD2 FIELD4 FIELD5 RESTOFFIELDS
do
print "$FIELD1 $FIELD2 $FIELD3 $FIELD4 $FIELD5 .000 $RESTOFFIELDS"
done
The typeset feature performs a lot of formatting automatically without lengthy tests.
Bill Hassell, sysadmin