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
dos2unix(1)						      General Commands Manual						       dos2unix(1)

NAME
dos2unix - DOS/MAC to UNIX text file format converter SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates dos2unix under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. dos2unix Convert and replace a.txt. Convert and replace b.txt. dos2unix a.txt b.txt dos2unix -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format. dos2unix a.txt -c iso b.txt dos2unix -c ascii a.txt -c iso b.txt dos2unix -c mac a.txt b.txt Convert and replace a.txt while keeping original date stamp. dos2unix -k a.txt dos2unix -k -o a.txt Convert a.txt and write to e.txt. dos2unix -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. dos2unix -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. dos2unix a.txt -n b.txt e.txt dos2unix -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHORS
Benjamin Lin - <blin@socs.uts.edu.au> Bernd Johannes Wuebben (mac2unix mode) <wuebben@kde.org> MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
unix2dos(1) mac2unix(1) 1995.03.31 dos2unix v3.0 dos2unix(1)
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy