Since you refused to answer most of my questions, I will make one final attempt at trying to handle a general case. Since you didn't give enough information about the desired output format, I'll make some code that reads input strings and produces output strings with the following characteristics:
Input strings to be processed are lines in a file named file.
Each input string is an alphanumeric string ending in one or more decimal digits.
The string of trailing decimal digits identify an integer value that can be stored in an object equivalent to a C language signed long integer.
The length of the leading alphanumeric character string before the ending decimal digits varies in length from 0 characters up to the number of characters in the input string minus 1.
The decimal digits at the end of each output string are to be padded with leading zeros such that the string of decimal digits at the end of each output string contains the same number of ending decimal digits as the longest string of ending decimal digits in the input strings being processed.
The output string will contain the leading alphanumeric characters before the ending string of decimal digits found in the input string followed by the decimal digit string found at the end of that input string with leading zeros added as described in #5 above.
If the input does not conform to the above specifications, the output format is undefined.
Since you refused to specify the length of the desired ending zero filled decimal digit output string, I'll use awk for this example to avoid reading the input file twice:
If file contains:
it produces the output:
and if file just contains the 1st four input lines shown above, the output would be:
Last edited by Don Cragun; 09-11-2015 at 06:10 PM..
Reason: Fix typo in Item #6 in the list.
This User Gave Thanks to Don Cragun For This Post:
Hi Folks!
Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: :confused:
My shell script snippet looks like this:
#!/bin/sh
..
COMMAND="find ./* -printf '%p %m %s %u %g \n'"
echo "Command: ${COMMAND}"... (1 Reply)
Hi all,
My simple AWK code does C = A - B
If C can be a negative number, how awk printf formating handles it using string format specifier.
Thanks in advance
Kanu
:confused: (9 Replies)
I am trying to use printf with a character string that is used within a do loop. The problem is that while in the loop, the printf prints the variable name instead of the value. The do loop calls the variable name from a text file (called device.txt):
while read device
do
cat $device.clean... (2 Replies)
Hi I'm having a problem with converting a file:
ID X
1 7
1 8
1 3
2 5
2 7
2 2
To something like this:
ID X1 X2 X3
1 7 8 3
2 5 7 2
I've tried the following loop:
for i in `cat tst.csv| awk -F "," '{print $1}'| uniq`;do grep -h $i... (4 Replies)
hi all
can any one help me to understand this
bdf -t vfxs | awk '/\//{printf("%-30s%-10s%-10s%-10s%-5s%-10s\n",$1,$2,$3,$4,$5,$6)}'
i want to understand the numbers %-30S% (4 Replies)
Hi Friends,
I am trying to insert lines of the below format in a file:
# x3a4914 Joe 2010/04/07
# seh Lane 2010/04/07
# IN01379 Larry 2010/04/07
I am formatting the strings as follows using awk printf:
awk 'printf "# %s %9s %18s\n", $2,$3,$4}'
... (2 Replies)
I want to print a string say "str1 str2 str3 str4" using printf.
If I try printing it using printf it is printing as follows.
output
-------
str1
str2
str3
str4
btw I'm working in AIX.
This is my first post in this forum :)
regards,
rakesh (4 Replies)
Hi Experts,
Quick question:
I am trying to get the output with decimal and floating point but not working:
echo "20.03" | awk '{printf "%03d.2f\n" , $0 }'
020.2f
How to get the output as :
020.03
Thank you. (4 Replies)
Hi All
I am working to process txt file into csv commo separated.
Input.txt
1,2,asdf,34sdsd,120,haahha2
2,2,wewedf,45sdsd,130,haahha
.....
....
Errorcode.txt
120
130
140
myawk.awk code:
{
BEGIN{
HEADER="f1,f2,f3,f4,f5,f6" (4 Replies)
Hello,
I am looking for a method to use in my bash script which allows me to use long strings with all special characters.
I have found that printf method could be helpful for me but unfortunately, when I trying
root@machine:~# tevar=`printf "%s%c"... (2 Replies)