Sponsored Content
Top Forums Shell Programming and Scripting Need help to understand ksh script Post 302514211 by mirni on Friday 15th of April 2011 05:45:00 AM
Old 04-15-2011
Oh my... ok, let me give it a shot:
Code:
#!/bin/ksh
#%W% %I% %D% %T% ---- these are comments (starting with #)
#%W%G --- they don't do anything


The beginning of this line here:
Code:
//g'


Seems like something's missing there. To me it looks like the end of some global substitution using sed, something like
Code:
 sed 's/delete_this_pattern//g'

Furthermore, you don't have any input specified there... Where is the data, that these filters operate on, coming from? A file? Pipe?
It's gonna want input from stdin...
if statement needs to be closed with 'fi'.

Now for the filters alone, they don't look extremely difficult to understand.

[CODE]
egrep -v '(.sh:|.kshSmilie'[/CODE] is gonna skip lines that contain '.sh:' alebo '.ksh:'
The second filter
Code:
sed 's/^.*://g'

will erase everything before the last colon, including the colon itself. 'g' at the end is not needed.The third filter:
Code:
sed 's/^M//g'

will erase all characters "^M". (these can be seen as delimiters in some windows files.)

Fourth:
Code:
grep -v '^[ s]*#'

will skip (not print for further processing) lines that start with a space or letter 's' present zero or more times and a pound sign. E.g. a line like this:
Code:
sss ss s#something

would be skipped. The line
Code:
sss ttt ff#blah

would not be skipped (there are other chars before pound sign). The line has to contain the pound sign, to be skipped. The next filter
Code:
egrep -i '(.dat|.ctl)'

will keep only lines with '.dat' or .ctl, case insensitive (e.g. '.cTl' would be matched)

This long filter:
Code:

Code:
sed -e 's/^.*=//g' -e 's/,/ /g' -e 's/;/ /g' -e 's/"//g'


has four parts: 1. it erases everything before an equal sign, including.
2. changes all commas to spaces
3. changes all semicolons to spaces
4. erases all double quotes.

This filter
Code:
tr ' ' '\n'

Will change (translate) all spaces into newlines

This one
Code:
sed 's/[    ]*//g'

will erase all spaces (there are none by this time)
This
Code:
 sed '/^$/d'

will erase all empty lines.
And finally,
Code:
sort -u | nawk -F"/" '{print $NF}'


will sort the output lines, printing only the first occurence, if there are multiple same lines; and print only the part of the string after the last slash (-F"/" use slash as delimiter; print $NF, print last field).
The output is gonna be written into file $FILE, which, if exists is gonna get overwritten.

Search for "sed regular expressions" for further explanations.

This script is incomplete, and won't work as is.
This User Gave Thanks to mirni For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

2. Shell Programming and Scripting

Can't understand the script

I am relatively new to Shell Scripting. I can't understand the following two scripts. Can someone please spare a minute to explain? 1) content s of file a are (021) 654-1234 sed 's/(//g;s/)//g;s/ /-/g' a 021-654-1234 2)cut -d: -f1,3,7 /etc/passwd |sort -t: +1n gives error (3 Replies)
Discussion started by: shahdharmit
3 Replies

3. Shell Programming and Scripting

Help to understand the script

Hi All; Is there anybody can explain this script please? trap 'C_logmsg "F" "CNTL/c OS signal trapped, Script ${G_SCRIPTNAME] terminated"; exit 1' 2 trap 'C_logmsg "F" "Kill Job Event sent from the Console, Script ${G_SCRIPTNAME] terminated"; exit 1' 15 (3 Replies)
Discussion started by: thankbe
3 Replies

4. Shell Programming and Scripting

Need to understand the script pls help

Can u please explain what it is doing #!/bin/sh fullyear=`/home/local/bin/datemmdd 1`"."`date +%Y` uehist=/u05/home/celldba/utility/ue/prod/history echo $fullyear cd $uehist ls -ltr pwroutages.master.$fullyear* | awk '{print $9}' > /u01/home/celldba/tmp/pwroutages_master_all_tmp while... (2 Replies)
Discussion started by: raopatwari
2 Replies

5. Shell Programming and Scripting

Help me understand the Perl script..

#!/usr/bin/perl use strict; use warnings; print "Demo of array slicing \n"; my @abc="a b c d e f g h i j k l m n o p q r s t u v w x y z"; my @a=@abc; my @random=@abc; my @comp=@abc; my @comp1=(@abc,"Hello",@abc); print "abc is @abc \n"; print "a is @a \n"; print "random is @random \n";... (1 Reply)
Discussion started by: dnam9917
1 Replies

6. Shell Programming and Scripting

Need help to understand this small script

Hi Guys, I need to understand below scipt:- -bash-3.00$ cat rsync-copy.ksh #!/usr/5bin/ksh batch <<%EOF% echo "/usr/local/bin/rsync --rsync-path=/usr/local/bin/rsync -a --stats /usr/openv/ /OpenvBCK" > openv.LOG # CG /usr/local/bin/rsync ... (6 Replies)
Discussion started by: manalisharmabe
6 Replies

7. Shell Programming and Scripting

Help to understand a script

Hello world! Can someone please explain me how this code works? I'ts supposed to find words in a dictionary and show the anagrams of the words. { part = word2key($1) data = $1 } function word2key(word, a, i, x, result) { x = split(word, a, "") asort(a) ... (1 Reply)
Discussion started by: jose2802
1 Replies

8. Shell Programming and Scripting

Need help to understand the below shell script

Please help me to understand the below 3 lines of code.execute shell in jenkins 1)APP_IP=$( docker inspect --format '{{ .NetworkSettings.Networks.'"$DOCKER_NETWORK_NAME"'.IPAddress }}' ${PROJECT_NAME_KEY}"-CI" ) 2)HOST_WORKSPACE=$(echo ${WORKSPACE} | sed... (1 Reply)
Discussion started by: naresh85
1 Replies

9. UNIX for Beginners Questions & Answers

Help me understand this script

#!/bin/awk -f BEGIN {i=1;file="modified.txt"} { if ($0 !~ /^DS:/) {print $0 >> file} else { if ($0 ~ /^DS:/) {print "DS: ",i >> file;if (i==8) {i=1} else {i++}}; } } END {gzip file} Can someone explain to me how this above script works, I got it from a friend but not able... (3 Replies)
Discussion started by: Kamesh G
3 Replies
All times are GMT -4. The time now is 09:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy