General question about the relationship between KSH and sed/grep/awk etc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting General question about the relationship between KSH and sed/grep/awk etc
# 1  
Old 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
# 2  
Old 03-05-2009
Many common shells are different extensions on old-fashioned sh, which didn't even have arrays, so basic can mean really, really basic, and prevents really radical modification of the syntax. Efficiency's often aided by making some common things built-in -- it wouldn't have a builtin awk or sed, but would have a built in echo, read, etc. Creative use of things like the field seperator can also be used to help deal with strings but it's not a general-purpose do-everything construct. Though BASH has regexes these days...
# 3  
Old 03-05-2009
Yes - you're getting it.

The shell is just a glue that holds everything else together with its own restricted functionality. As Unix is so efficient at parameter passing, STDIN, STDOUT etc and environment inheritance from parent to child process, there's no great reason to include string manipulation or even arithmetic in the shell when there are so many other good ways - sed, awk, perl - of doing things.

Unix scripting or even command line use is all about the toolkit and experience becomes a matter of choosing the right tool for the job at the time. This forum clearly shows, though, that there are many ways of using different tools to get the same end results.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

General find /grep question: files with lines ending in r

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

2. Shell Programming and Scripting

Grep / awk /sed question

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

3. Linux

General compression question

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

4. Shell Programming and Scripting

Question grep and sed

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

5. Shell Programming and Scripting

question on sed grep awk from variable

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

6. Shell Programming and Scripting

sed / grep question

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

7. Shell Programming and Scripting

general question?

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

8. UNIX for Dummies Questions & Answers

General Question

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

9. Shell Programming and Scripting

script ksh/awk/grep

How can I extract the 9th line of a text file. thanks vm.:confused: (2 Replies)
Discussion started by: hoang
2 Replies

10. UNIX for Dummies Questions & Answers

General Proxy Question

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
Login or Register to Ask a Question