03-05-2009
General question about the relationship between KSH and sed/grep/awk etc
Greetings all,
Unix rookie here, just diving into ksh scripting for the first time.
My question may seem confusing but please bear with me:
If I'm understanding everything I'm reading properly, it seems like the ksh language itself doesn't have a lot of string manipulation functions of its own - as a matter of fact all it really seems to have is variables, arrays, and control flow (i.e. loops, if/else/fi etc.)
Therefore, if one wants to write a ksh script to do, for example, extensive string manipulation, validation, reporting etc., one MUST make use of a utility like awk, or sed, or grep, or even something simple like cut to manipulate strings, and use something like command substitution to assign the return value to a variable, i.e.
sMyString1='hello,hi,what's up?'
sMyString2 = (echo $sMyString1 | cut -d',' -f2)
and then sMyString2 would be "hi"
I deviated from my original question a bit there.
Basically, I just want to make sure I'm understanding this correctly that ksh itself doesn't really have a great deal of built-in commands and functions and that you really do have to avail yourself of built-in (or downloaded/installed) unix programs and command substitution/redirection to do any complex programming.
Does it seem like I'm "getting it"?
Thanks buckets
DTXCF
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
This is quite a general question:
I am trying to detect whether people accessing my network are using a proxy server. This is *not* to ensure that web pages are not cached!
The only way that I can think of doing this is to intercept at packet level and examine the source port for... (1 Reply)
Discussion started by: sam_pointer
1 Replies
2. Shell Programming and Scripting
How can I extract the 9th line of a text file.
thanks vm.:confused: (2 Replies)
Discussion started by: hoang
2 Replies
3. UNIX for Dummies Questions & Answers
Hi, I've been racking my brains trying to remember, but, whats the command to change the default shell? I'm currently always in the Korn shell and I want to start out in the Bash shell. I'm running a variant of BSD I guess in Mac OS X 10.2.2 and Mandrake. Thanks.
ccindyderek:confused: (4 Replies)
Discussion started by: ccindyderek
4 Replies
4. Shell Programming and Scripting
Perl, Python, and PHP are these languages easy to use? Are they command line or are they part of a GUI? (2 Replies)
Discussion started by: wmosley2
2 Replies
5. Shell Programming and Scripting
Hello,
I am new to shell scripting.
I have a input file: Few lines of the input file has the following.
/a0012/abcd12/abcd12
/a0003/xyzab1/lmno123
/a0006/pqrst1/abcde12
In my output file, I only need to get anything that is between the first and second '/' of each line: exampple:... (6 Replies)
Discussion started by: hemangjani
6 Replies
6. Shell Programming and Scripting
i am still confusing on how to use sed, grep and awk if the input is not a file but a variable.
such as:
a="hello world"
b="how are you"
c="best wish to you"
d="222,333,444"
what if i want to check which variable $a,$b,$c,$d have contain "you"
what if i want to replace the word "you"... (9 Replies)
Discussion started by: 3Gmobile
9 Replies
7. Shell Programming and Scripting
hi everybody
i have this script and it work's if i use a single variable in grep, but when i put $searchterm_ the script stops work
i have a problem too in sed, because i don't know how i can search and replace more than one item, in this case is >>> $searchterm/$replaceterm and... (4 Replies)
Discussion started by: felito
4 Replies
8. Linux
I am looking for an alternate solution other than gzip or bzip2 to compress files that are 3 to 4 GB each and will be hundreds per day. Aside from increasing storage anybody found a good tool? (5 Replies)
Discussion started by: mykey242
5 Replies
9. Shell Programming and Scripting
Hi All,
I have a file with following sample data. I am also attaching the file.
(Est) (Est) Jobs Sch
Workstation Job Stream SchedTime State Pr Start Elapse # OK Lim
POOL #ACR_BILLING 0005 08/15 ... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies
10. UNIX for Dummies Questions & Answers
I am trying to find files that have lines in them that end in an r. I have been able to locate files by using the following command:
find . -type f -name "*RECORDS"| xargs grep -l r$
However, I now want to find files that don't end in r anywhere. That means that no sentences or lines in... (9 Replies)
Discussion started by: newbie2010
9 Replies
LEARN ABOUT OPENDARWIN
zgrep
ZGREP(1) General Commands Manual ZGREP(1)
NAME
zgrep - search possibly compressed files for a regular expression
SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename...
DESCRIPTION
Zgrep is used to invoke the grep on compress'ed or gzip'ed files. All options specified are passed directly to grep. If no file is speci-
fied, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and
fed to grep.
If zgrep is invoked as zegrep or zfgrep then egrep or fgrep is used instead of grep. If the GREP environment variable is set, zgrep uses
it as the grep program to be invoked. For example:
for sh: GREP=fgrep zgrep string files
for csh: (setenv GREP fgrep; zgrep string files)
AUTHOR
Charles Levert (charles@comm.polymtl.ca)
SEE ALSO
grep(1), egrep(1), fgrep(1), zdiff(1), zmore(1), znew(1), zforce(1), gzip(1), gzexe(1)
ZGREP(1)