awk script

awk script

Post by David » Wed, 15 Feb 2006 20:13:42



Hi all,

I need to modify an output of a script with awk.
I need to see only the first 16 characters of this output, cutting the
remaing

so, if I have

abcdefghijklmnopqrstuvwxyz as output I just want to see it 16 chara
lenght

abcdefghijklmnop (of course I would like to see the output if it is
shorter than 16 char)

I cannot understand how to do this in awk man
Cheers :)

 
 
 

awk script

Post by Giorgos Keramida » Wed, 15 Feb 2006 22:11:11



Quote:> Hi all,

> I need to modify an output of a script with awk.
> I need to see only the first 16 characters of this output, cutting the
> remaing

> so, if I have

> abcdefghijklmnopqrstuvwxyz as output I just want to see it 16 chara
> lenght

> abcdefghijklmnop (of course I would like to see the output if it is
> shorter than 16 char)

> I cannot understand how to do this in awk man
> Cheers :)

Then don't do it in awk...

    $ echo 'abcdefghijklmnopqrstuvwxyz' | cut -c 1-16
    abcdefghijklmnop
    $

 
 
 

awk script

Post by David » Wed, 15 Feb 2006 23:07:20


yes!
I discovered 15 minutes ago...

the easyest way to do something is do it in the easy way!
Cheers

 
 
 

awk script

Post by Richard L. Hamilt » Thu, 16 Feb 2006 08:22:51





>> Hi all,

>> I need to modify an output of a script with awk.
>> I need to see only the first 16 characters of this output, cutting the
>> remaing

>> so, if I have

>> abcdefghijklmnopqrstuvwxyz as output I just want to see it 16 chara
>> lenght

>> abcdefghijklmnop (of course I would like to see the output if it is
>> shorter than 16 char)

>> I cannot understand how to do this in awk man
>> Cheers :)

> Then don't do it in awk...

>     $ echo 'abcdefghijklmnopqrstuvwxyz' | cut -c 1-16
>     abcdefghijklmnop
>     $

Or do if you like, it's not that hard:

    $ echo 'abcdefghijklmnopqrstuvwxyz' | awk '{print substr($0,1,16)}'
    abcdefghijklmnop

But be warned: /usr/bin/awk can't handle really long lines; nawk is
probably better, /usr/xpg4/bin/awk better still, and if you have it,
GNU awk (sometimes gawk) can handle pretty much anything.

--

Lasik/PRK theme music:
    "In the Hall of the Mountain King", from "Peer Gynt"

 
 
 

awk script

Post by nick.secco.. » Thu, 16 Feb 2006 21:52:09


Quote:>From the dim and distant, something like this would do the job,

although there are lots of other ways you could do it without awk:

echo "mystring" | awk '{ print substr($0, 1, 16) }'

Cheers

 
 
 

1. awk script

Each day I have a file generated with several hundred lines. I'd like to
create a single awk script that would print to screen only the line(s)
with the most fields. I've futzed around with this and come to a dead
end, brain-dead probably. Found lots of interesting examples that help
not. O'Reilly's sed & awk book hasn't provided the inspiration I'd hoped
for. A nudge in the right direction sure would be appreciated.

Bill Piety
Registered Linux user #193275

2. Using drive: 0 partition: 3 ... and then nothing

3. Need help with simple awk script

4. IOT Instruction

5. awk script that works like "cut"

6. curses and color

7. getopts / awk script

8. BroadVision

9. awk scripting

10. awk script fails on solaris 2.4

11. 'getline < "-" in awk script does not work!

12. Can you launch an awk script this way?

13. Help with awk script