Search Results

Search: Posts Made By: sumguy
1,258
Posted By RudiC
I'd propose to drop the "command substitution" $(...
I'd propose to drop the "command substitution" $( ... ) as it's not needed in above construct.


If you have all target lines in a file, and you are sure they occur not more than once in the large...
1,258
Posted By rbatte1
I would go further:-if $(grep -q "now is the...
I would go further:-if $(grep -q "now is the time" 1000linefile.txt)
then
echo "It's a HIT"
else
echo "Missed"
fiThe extra benefit is that the -q flag will cause the grep to exit...
1,258
Posted By vgersh99
a bit simplified: if [ $(grep -c...
a bit simplified:

if [ $(grep -c mySearchPattern myFile) == 0 ]; then
echo 'not found'
else
echo 'found'
fi
2,652
Posted By jim mcnamara
As general note - some bash regex strings fail...
As general note - some bash regex strings fail when used directly on the command line. Spaces in regex are an example.
It is probably best practice to make them variables:
bash - Capturing Groups...
2,652
Posted By jim mcnamara
bash supports regex, tried that? ...
bash supports regex, tried that?

string="SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.1745"
regex1="sysObjectID"
regex2="[0-9]{4}$"
if [[ "$string" =~ $regex1 ]] then
[[...
2,652
Posted By RudiC
How about while read line do [[ "$line"...
How about
while read line
do [[ "$line" =~ sysName ]] && sysN=${line##* }
[[ "$line" =~ sysObjectID ]] && sysO=${line##*.}
[[ "$line" =~ sysDescr ]] && {...
2,630
Posted By RudiC
I'm afraid - no. That's a feature of bash - I...
I'm afraid - no. That's a feature of bash - I can't talk for other shells.
1,476
Posted By vidyadhar85
simple would be.. sed -ne '/is/p' -e...
simple would be..


sed -ne '/is/p' -e '/for/{p;q}' filename
1,109
Posted By MadeInGermany
If you read the entire file into an array you...
If you read the entire file into an array
you can print the array like that - without a loop.
@lines = <IN>;
print grep /\Q$ARGV[0]\E/, @lines;
Or even directly from the file
print grep...
1,109
Posted By MadeInGermany
#!/bin/perl $err=1; open (IN,"peeplist") or...
#!/bin/perl
$err=1;
open (IN,"peeplist") or die;
while (<IN>) {
if (/\b$ARGV[0]\b/) {print; $err=0;}
}
close (IN);
if ($err==1) {print STDERR "not found\n"}
exit $err;This uses perl's $_...
2,317
Posted By clx
This is listed in perlfaq. have a look How...
This is listed in perlfaq.

have a look How can I tell whether a certain element is contained in a list or array?...
10,496
Posted By Don Cragun
Depending on how many <NAME> lines there are in...
Depending on how many <NAME> lines there are in the input file, you might have to close the output files when you're done writing to them:
{if(FN)close(FN);FN="File"++i".txt"}
10,496
Posted By RudiC
Reedited - fine! Do you think you find the right...
Reedited - fine! Do you think you find the right answer with the starting point given above?
9,919
Posted By balajesuri
sed 's/^[^ ]*/&,/' file
sed 's/^[^ ]*/&,/' file
9,919
Posted By Scott
You can also do that slightly shorter with: ...
You can also do that slightly shorter with:

$ awk '$1=$1","' file

but neither will maintain the spacing between fields. Perhaps using awk's sub function would be the answer.

This seems a bit...
9,919
Posted By Yoda
You can use awk instead:- awk ' { $1 = $1",";...
You can use awk instead:-
awk ' { $1 = $1","; print; } ' input_file
Showing results 1 to 16 of 16

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