Thanks Corona688! This what I tried by combining Don's reply.
but did not work. What did I miss?
Following your attempt a little closer than the way Corona688 did it...
This is an awk script, not a shell script; so $ before a variable name references the field named by contents of the variable instead of the contents of the variable AND awk variables are not expanded in quoted strings AND ${#var} and $((expr)) are shell expressions that are not valid awk expressions.
If what you are trying to do is produce 8 character output strings (assuming the length of the input string is never more than 8 characters) with varying length alphabetic and numeric parts in the input, try:
Assuming test.file contains:
as shown in post #18 in this thread, it produces the output:
Remember the input file format I specified in post #10 in this thread. Your sample input file has trailing spaces (violating item #2: Each input string is an alphanumeric string ending in one or more decimal digits.)
If we remove all of the trailing spaces from file.test or change all occurrences of $0 in the above script to $1 (so we just look at the first field instead of the entire line), the output produced is:
which I assume is closer to what you were trying to do.
As a learning exercise, can you explain why the awk script Corona688 suggested didn't have a problem with trailing spaces while my script above does have a problem with trailing spaces?
And, no, I'm not a lawyer. But I did like the Perry Mason, Matlock, and Boston Legal TV series. And, in my last job, my boss referred to me as his standards lawyer because he could get me to answer any questions about why we were failing POSIX/UNIX standards conformance tests and directions on how to fix our code (when we had a bug) or how to file a bug report against the test suite (when there was a bug in the test suite or it was assuming behavior above and beyond what the standards require).
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)