Sponsored Content
Top Forums Shell Programming and Scripting Using cat and pipeline to execute script Post 303007662 by crepe6 on Sunday 19th of November 2017 09:50:50 PM
Old 11-19-2017
Using cat and pipeline to execute script

hi this is a homework assignment i need some help with

it mostly works.

script file

Code:
#!/usr/bin/env bash

#create dictionary file
grep -E '.{3}' /usr/share/dict/british-english > db.txt

#create remove_word to test file
touch removeW.txt

#palindrome function
palin()
{
        sed 's/[0-9]*//g;s/[/\._-]//g'\
	|tr -d '[[:punct:][:digit:]@]' \
    	| sed -E -e '/^(.)\1+$/d' \
    	| tr -s '[[:space:]]' \
    	| tr '[[:space:]]' '\n'        
}

paste <(palin <"$1") <(palin <"$1" | rev) \
  | awk '$1 == $2 && (length($1) >= 3) { print $1 }' \
  | sort | uniq -ic > done.txt

#removes repeated letters 
awk '{l=$0; if (length($2)!=gsub(substr($2,1,1), "", $2)) print l}' done.txt > finish.txt

#compares text files to remove words
grep -vwF -f db.txt finish.txt > removeW.txt|
grep -vwF -f removeW.txt finish.txt|
awk '!/ere|eke/'

#rm db.txt finish.txt removeW.txt done.txt

i can get this command to work

Code:
./script textfile

and it gives mostly the correct output.

but i also want to be able to invoke a command such as

Code:
cat textfile | script > outputfile

i'm not sure where to add the arguments in the script. I tried adding parameters on the paste line but get errors that file/directory not existing. I also tried an if statement, something i found.

Code:
if (($#)) ; then
     process "$1"
else
     cat | process
fi

tried different statements but it didn't work.

i'm using ubuntu lastest version i think.

any hints or help would be great thank you.

Last edited by crepe6; 11-19-2017 at 10:54 PM.. Reason: formatting
 

9 More Discussions You Might Find Interesting

1. Programming

C program help please! input from pipeline

I have a project where I have to use bzcat to uncompress a file and use that output as the data to run another program on. I understand that you would do (bzcat filename.bz2 ! program name) but then how do you access that data in the c program??? Please help thanks (2 Replies)
Discussion started by: kinggizmo
2 Replies

2. UNIX for Dummies Questions & Answers

Unix Pipeline help

Does anyone know how to answer this? I have tried many different commands, I just cant get it right..... Search the file 'data' for all of the lines that contain the pattern 'unx122' and put those lines in the file 'matches'. (2 Replies)
Discussion started by: netmaster
2 Replies

3. Shell Programming and Scripting

script execute or no execute

o hola.. Tengo un script que se ejecuta bajo una tarea del CronJOb del unix, tengo la version 11 de unix, mi script tiene un ciclo que lee unos archivos .txt luego cada uno de esos archivos debe pasar por un procedimiento almacenado el cual lo tengo almacenado en mi base de datos oracle 10g,... (4 Replies)
Discussion started by: Kespinoza97
4 Replies

4. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

5. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

6. Shell Programming and Scripting

uniq -c in the pipeline

Hello gurus - I must be missing something, or there is a better way - pls enlighten me I'm on a Solaris 10 vm running the following pipeline to reduce some apache logs (actually lynx dumps of /server-status/ when threads are above a threshold) to a set of offending DDoS IP addresses. awk... (10 Replies)
Discussion started by: fletch00
10 Replies

7. Shell Programming and Scripting

If statement with pipeline

Hi Can anybody please explain me the following script in detail Value=`echo "if ( ${FACTOR} >= 1 ) {1}" | bc` What does "{1}" mean to here ? (3 Replies)
Discussion started by: Priya Amaresh
3 Replies

8. Shell Programming and Scripting

Command pipeline trouble

Hello, I am attempting to ssh to a server and run a set of commands on a remote set of servers. I am getting the following error below, I am thinking quotes may be the problem. This command works on the local machine in bash. Not when I ssh to a remote server. Basically the command should... (3 Replies)
Discussion started by: jaysunn
3 Replies

9. UNIX for Dummies Questions & Answers

Form a pipeline script with series of steps

Hello all, This maybe a dumb question, I have a series of awk command liners, perl and C executables that I usually run in a particular order to get an output. I need 2 files as input and then , a series of outputs are produced which pipe into the next step etc. I am usually able to paste... (3 Replies)
Discussion started by: senhia83
3 Replies
GZEXE(1)						      General Commands Manual							  GZEXE(1)

NAME
gzexe - compress executable files in place SYNOPSIS
gzexe [ name ... ] DESCRIPTION
The gzexe utility allows you to compress executables in place and have them automatically uncompress and execute when you run them (at a penalty in performance). For example if you execute ``gzexe /bin/cat'' it will create the following two files: -r-xr-xr-x 1 root bin 9644 Feb 11 11:16 /bin/cat -r-xr-xr-x 1 bin bin 24576 Nov 23 13:21 /bin/cat~ /bin/cat~ is the original file and /bin/cat is the self-uncompressing executable file. You can remove /bin/cat~ once you are sure that /bin/cat works properly. This utility is most useful on systems with very small disks. OPTIONS
-d Decompress the given executables instead of compressing them. SEE ALSO
gzip(1), znew(1), zmore(1), zcmp(1), zforce(1) CAVEATS
The compressed executable is a shell script. This may create some security holes. In particular, the compressed executable relies on the PATH environment variable to find gzip and some other utilities (tail, chmod, ln, sleep). BUGS
gzexe attempts to retain the original file attributes on the compressed executable, but you may have to fix them manually in some cases, using chmod or chown. GZEXE(1)
All times are GMT -4. The time now is 07:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy