Using cat and pipeline to execute script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using cat and pipeline to execute script
# 1  
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
# 2  
Old 11-20-2017
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

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