03-05-2007
Pipelines
Now before this thread gets closed, please be aware this is not classwork or homework, I am trying to learn unix by myself, and have come stuck below. So it is a pointless to close this thread, as I am trying to improve my unix by asking advice from people. That is what I assume a forum is for!
I am trying to work out how to complete this question, and after learning a bit more unix. i have written an answer to it. Can anyone check to see if it is correct and what improvements need to be made?
Write a pipeline that updates the content of a file (a file of your choice) by replacing all matches of the word ‘and' with the symbol ‘&' and by replacing the end of each line with the user login name. If the command completes successfully it should print ‘YES', otherwise it should print ‘NO'.
cat text.txt | sed -e s/and/$USER/g -e s/$/”&”/g | cat -> text.txt
&& echo yes || echo no
thanks
vish
4 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
howdy all,
i've been trying to find info on piping info between multiple commands from the command line, but i've been unable to find any examples of piping continuous data through a chain of commands. basically, i'm trying to parse data from the top command and send it out over udp to another... (1 Reply)
Discussion started by: ohhmyhead
1 Replies
2. Shell Programming and Scripting
Hi,
As per shell docs because commands in pipelines are run as separate processes,
variables set in a pipeline have no effect on the parent shell
In the sample below I am unable to set variable in Proc1 so that I can see it in the main program
Is there any work around ?
Thanks
Zam... (4 Replies)
Discussion started by: zam
4 Replies
3. UNIX for Dummies Questions & Answers
How would I combine commands in a pipeline to produce an alphabetized list of who's online at a particular moment?
Then:
How would I take that pipeline and turn it into a command called "whoison"? (1 Reply)
Discussion started by: greeky
1 Replies
4. Shell Programming and Scripting
What if you want to have just one single pipeline that will create a file (let's say x) and we want all the content from another file (we can call it y), one word per line? (7 Replies)
Discussion started by: sarahahah
7 Replies
RPL(1) BSD General Commands Manual RPL(1)
NAME
rpl -- replace strings in files
SYNOPSIS
rpl [-LhiwbqvsRepfdt] [-xSUFFIX] <old_string> <new_string> <target_file ...>
DESCRIPTION
Basic usage is to specify two strings and one or more filenames or directories on the command line. The first string is the string to
replace, and the second string is the replacement string.
-h, --help
A short help text.
-L, --license
Show the license and exit.
-xSUFFIX
Search only files ending with SUFFIX, e.g. ``.txt''. May be specified multiple times.
-i, --ignore-case
Ignore the case of old_string.
-w, --whole-words
Make old_string match only on word boundaries.
-b, --backup
Move the original files to filename~ before replacing them.
-q, --quiet
Quiet mode.
-v, --verbose
Verbose mode.
-s, --dry-run
Simulation mode, no files are changed.
-R, --recursive
Recurse into subdirectories.
-e, --escape
Expand escape sequences in old_string and new_string. Examples of escape sequences are '
' (new-line), ' ' (tab), 'x42' (hexadec-
imal number 42), '