Hot answers tagged

3

@cuonglm's comment illustrates how you can do this with sed: sed -e 's/.*\(Apple\)/\1/' input.txt You might also consider using good old grep: grep -o 'Apple.*' input.txt Caveat 1 - I don't have any solaris handy, so it might be that the solaris grep doesn't have the -o option. YMMV. Caveat 2 - If your input file has lines that don't contain any ...


3

If your not familiar with "vi" or "emacs" prompt commands the best would be to use the fc shell built-in command look at the "fc" help into the man sh-posix manpage. Use the mouse to copy paste the commands. The HP-UX shell is /usr/bin/sh the "POSIX shell" which command prompt is close to the korn shell, by default it is set to the vi command mode "Esc" ...


3

GNU tar's --index-file option works well: tar cvf - ./foo 2>foo.err --index-file=foo.out | squish > foo.tar.S


2

In ksh, you can only use single digit for explicit file descriptor. With ksh93r and above, you can open more than 10 file descriptor by using the form: {var}>filename (bash and zsh copied this feature later). ksh will pick available file descriptor greater than or equal to 10, store file descriptor number in variable var: $ exec {var1}>/tmp/test1 ...


2

For HP-UX you need to press Esc+K and pressing again will cycle through the history. To search through the history you can Esc+/ Search string.


1

OSTYPE="`uname`" OSTYPE="${OSTYPE,,}" case "$OSTYPE" in *aix*) target=~/.kshrc ;; *linux*) target=~/.bash_profile ;; esac if [ -n "$target" ]; then echo "alias d='du -sm -- * 2>/dev/null | sort -nr | head -20'" >> "$target" fi


1

You asked for nawk or sed. As you mention ksh, why not do a pure shell version? The following runs in any POSIX compliant shell: p="Apple" while read line ; do case $line in (*$p*) echo $p${line#*$p};; esac done <<! john_Apple01_xyz_1 john_Fruit_Apple01_abc_c1 john_Apple21_trs_1 john_Fruit_Apple21_efg_1 john_Fruit_Apple21_tefg_1 ! This ...


1

It looks like your script file has DOS/Windows line endings, e.g. Carriage Return (^M, chr(13)) in addition to the Line Feed character. The output tester[2]: ^M: cannot execute [Permission denied] certainly looks like that. This would also explain why the file cannot be executed by the shell directly: It is looking for an executable named /bin/ksh^M ...


1

The $(cmd) syntax captures the standard output of cmd (stripped of trailing newline characters). So all you have to do is have getweek output the information: #! /bin/sh - date +%V # or %U or %W date outputs the week number on its stdout which it inherits from sh, which in the case of weeknum=$(getweek) is set to a pipe or socketpair by the shell at the ...


1

You can very well use echo for that purpose. $ cat new echo 1 $ number=$(./new) $ echo $number 1 I think that serves the purpose. Also note that new above is the script that you're gonna write. comment below if I mis-assumed something



Only top voted, non community-wiki answers of a minimum length are eligible