Search Results

Search: Posts Made By: demmel
10,307
Posted By neutronscott
I believe awk would be easier. Your logic would...
I believe awk would be easier. Your logic would be ! ( /^Eat/ && ! /apple/), or, following De Morgan's law:


$ awk '! /^Eat/ || /apple/' input
Drink a soda
Drink an apple juice
Eat an apple...
2,406
Posted By agent.kgb
if [ "$(uname)" == "AIX" ] ; then ECHO="print...
if [ "$(uname)" == "AIX" ] ; then
ECHO="print -R"
else
ECHO="echo"
fi

$ECHO "some text"
2,406
Posted By Scrutinizer
echo will give undetermined results across shells...
echo will give undetermined results across shells and/or platforms when using special characters. The best way to get predictable behavior is to use printf with a format specifier.
printf '%s\n'...
2,406
Posted By disedorgue
Hi, under bash, you have a set parameter to...
Hi,
under bash, you have a set parameter to control these:
$ shopt -s xpg_echo
$ echo 'foo\tbar'
foo bar
$ shopt -u xpg_echo
$ echo 'foo\tbar'
foo\tbar
$ echo -e 'foo\tbar'
foo bar
...
5,234
Posted By Scrutinizer
sed? What is the pattern on the third line?...
sed? What is the pattern on the third line? Otherwise try something like:
sed -n '/===/{N;/===.*\n===/{n;p;};}' file
5,234
Posted By senhia83
try this perl solution instead of sed... will...
try this perl solution instead of sed... will depend on the exact pattern..


perl -0pe...
5,234
Posted By MadeInGermany
This should work with all sed: sed ' ...
This should work with all sed:
sed '
/^====================/ {
N;/\n====================/ {
N;s/.*\n= Exit/= Exit/
}
}
' file
2,446
Posted By senhia83
Both gives me the same result though on cygwin ! ...
Both gives me the same result though on cygwin !

$ while read line; do echo "echo "\"This color is $line and will be ready ASAP"\""; done < tmp
echo "This color is yellow and will be ready ASAP"...
2,446
Posted By MadeInGermany
With your extra quotes the $line is not inside...
With your extra quotes the $line is not inside quotes, giving some vulnerability.
For demonstration, add another line with a * to file1.txt
BTW, Chubler's $(cat file1.txt) is also vulnerable.
2,446
Posted By Chubler_XL
Yes, but your xargs tweak deals with that nicely,...
Yes, but your xargs tweak deals with that nicely, I just don't like <file1.txt at the front :D

xargs printf 'echo "This color is %s and will be ready ASAP"\n' <file1.txt
2,446
Posted By Scrutinizer
Two quotes too many, which would leave the...
Two quotes too many, which would leave the variable unquoted.
while read line; do
echo "echo \"This color is $line and will be ready ASAP\""
done < file1.txt
2,446
Posted By MadeInGermany
printf is cool, let's put xargs on top! ...
printf is cool, let's put xargs on top!
<file1.txt xargs printf 'echo "This color is %s and will be ready ASAP"\n':cool:
2,446
Posted By Chubler_XL
couple of more options: sed 's/.*/echo "This...
couple of more options:

sed 's/.*/echo "This color is & and will be ready ASAP"/' file1.txt
printf 'echo "This color is %s and will be ready ASAP"\n' $(cat file1.txt)
2,446
Posted By senhia83
while read line; do echo "echo "\"This color is...
while read line; do echo "echo "\"This color is $line and will be ready ASAP"\""; done < file1.txt


with awk

awk '{print "echo ""\"This color is "$0" and will be ready ASAP\""}' file1.txt
1,971
Posted By gandolf989
Here are the files that you need. My name is...
Here are the files that you need. My name is Brian.
You should know that so you can add my name to
your assignment when you turn it in.

:D



$ cat ./bingo.sh
#!/bin/bash

if [ $# -lt 2...
4,275
Posted By Scrutinizer
That will print the newline at the wrong end of...
That will print the newline at the wrong end of the line, that is why it messes up. One way to achieve this might be:
awk 'NR>1 && !/^\+/{print RS}1 END{print RS}' ORS= file
1,562
Posted By Yoda
awk '!/^[0-9]/{ORS=FS}/^[0-9]/{ORS=RS}1' file
awk '!/^[0-9]/{ORS=FS}/^[0-9]/{ORS=RS}1' file
12,321
Posted By jcarrott
Thank you for the help, but as I stated in my...
Thank you for the help, but as I stated in my first reply - the double quotes caused an error.

sed: 0602-404 Function s/flag1/ cannot be parsed.

There is no error with the single quotes....
4,276
Posted By hanson44
The problem is that /bin/ksh apparently does not...
The problem is that /bin/ksh apparently does not exist on your system.

Please try the following, assuming it runs on your system:
$ cat file1
word1
word2
word3
$ cat file2
word1
word2 word3...
4,276
Posted By Yoda
Here is a KSH script using Associative Arrays for...
Here is a KSH script using Associative Arrays for counting words:
#!/bin/ksh

typeset -A word_ARR

while read line
do
for word in $line
do
((...
4,276
Posted By Yoda
I forgot to mention that you require KSH93 to...
I forgot to mention that you require KSH93 to support this code.

KSH88 does not support typeset option -a to define arrays.
4,276
Posted By RudiC
Well, then, use the -w switch to grep. This then...
Well, then, use the -w switch to grep. This then would yield exactly gary_w's result. But I'm not sure that this will work on all grep versions.
4,276
Posted By gary_w
Note that RudiC's method counts the word if it is...
Note that RudiC's method counts the word if it is part of another word. I do not know if this is the desired result as the original spec did not get that detailed. Just sayin'.
4,276
Posted By RudiC
Using gary_w's files, would this satisfy your...
Using gary_w's files, would this satisfy your needs:
$ grep -of x1.dat x2.dat| sort |uniq -c
3 word1
5 word2
8 word3


---------- Post updated at 12:50 ---------- Previous...
4,276
Posted By nithinsen
for i in $(cat file1); do echo -n "$i ";tr -s ' '...
for i in $(cat file1); do echo -n "$i ";tr -s ' ' '\n' < file2| grep -c "$i ";done > temp03


change echo -n to echo.
Showing results 1 to 25 of 28

 
All times are GMT -4. The time now is 08:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy