* Awk
@ 1998-11-20 5:00 GJH
1998-11-20 5:00 ` Awk Nikola Milutinovic
1998-11-20 5:00 ` Awk Doug Chapman USG
0 siblings, 2 replies; 5+ messages in thread
From: GJH @ 1998-11-20 5:00 UTC (permalink / raw)
I am looking for a awk statement that can read a number of characters from a
string. Does anyone has any clue how to accomplish this ?
for example a string : 'thisisastring' where I want the first four
characters : this.
Regards
--
G.J.Hilbrands DISCLAIMER : This statement is not an
KPN Telecom BV official statement from, nor does it
+31 050-5852781 represent an official position, of PTT
g.j.hilbrands@kpn-telecom.nl Telecom BV
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Awk
1998-11-20 5:00 Awk GJH
@ 1998-11-20 5:00 ` Nikola Milutinovic
1998-11-20 5:00 ` Awk Doug Chapman USG
1 sibling, 0 replies; 5+ messages in thread
From: Nikola Milutinovic @ 1998-11-20 5:00 UTC (permalink / raw)
GJH wrote:
>
> I am looking for a awk statement that can read a number of characters from a
> string. Does anyone has any clue how to accomplish this ?
>
> for example a string : 'thisisastring' where I want the first four
> characters : this.
man awk - see function substr
substr ("thisisastring", 1, 4)
Nix.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Awk
1998-11-20 5:00 Awk GJH
1998-11-20 5:00 ` Awk Nikola Milutinovic
@ 1998-11-20 5:00 ` Doug Chapman USG
1998-11-20 5:00 ` Awk Doug Chapman USG
1 sibling, 1 reply; 5+ messages in thread
From: Doug Chapman USG @ 1998-11-20 5:00 UTC (permalink / raw)
GJH wrote:
>
> for example a string : 'thisisastring' where I want the first four
> characters : this.
>
Sed works nicely:
echo thisisastring | sed 's/\(....\).*/\1/'
The \(....\) part means save the first 4 characters (due to the for . )
The .* just matches the rest of the string
The \1 means write out what was matched by what was in the
first set of \( \)
- Doug
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Awk
1998-11-20 5:00 ` Awk Doug Chapman USG
@ 1998-11-20 5:00 ` Doug Chapman USG
1998-11-22 5:00 ` Awk Nikola Milutinovic
0 siblings, 1 reply; 5+ messages in thread
From: Doug Chapman USG @ 1998-11-20 5:00 UTC (permalink / raw)
Doug Chapman USG wrote:
> >
> > for example a string : 'thisisastring' where I want the first four
> > characters : this.
> >
>
> Sed works nicely:
>
> echo thisisastring | sed 's/\(....\).*/\1/'
>
Sorry to followup to my own post but I guess it can
be done easily with awk:
echo thisisastring | awk '{printf ("%.4s\n",$1)}'
- Doug
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1998-11-22 5:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-20 5:00 Awk GJH
1998-11-20 5:00 ` Awk Nikola Milutinovic
1998-11-20 5:00 ` Awk Doug Chapman USG
1998-11-20 5:00 ` Awk Doug Chapman USG
1998-11-22 5:00 ` Awk Nikola Milutinovic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox