03-30-2012
Grepping using -w and dashes (-)
I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example:
hosta.something.com becomes hosta, and hosta is grepped with -w into the master list. The master list may return something like hosta.anything.internal.com which is fine because that's the suffix our supported list uses.
However, there are some hosts on our list named hosta-1, hosta-1-10, hosta-b-svr and so forth. When I grep -w hosta it will return all those others because the grep is not delimited by a dash. This seems like a particularly difficult problem because if the arbitrary list DOES supply a hostname with a dash I still need to be able to grep that.
I think this is an impossible situation but just thought I'd ask.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I have a file containing social security numbers with the format ###-##-####. I need to read each record in this file, reformat the SSN to the format #########, and write the record with the reformatted SSN to a new file. I am a UNIX newbie. I think I need to use either the sed or awk commands, but... (2 Replies)
Discussion started by: Marcia P
2 Replies
2. UNIX for Dummies Questions & Answers
function date_diff
{
integer _dt1=$(date_to_num ${1:?})
integer _dt2=$(date_to_num ${2:?})
integer _ndt=0
if ]
then
((_ndt=_dt2-_dt1))
fi
print -- $_ndt
}
What does double dash '--' indicate ?
Can anyone please answer this (2 Replies)
Discussion started by: systemsb
2 Replies
3. UNIX for Dummies Questions & Answers
Hey guys,
I'm trying to grep for two things out of a file and I got that working but why is it randomly throwing "--" in the output? Is there a simple way to get rid of them? It only seems to do it when the line above what im looking for has numbers in it.
$ egrep -i -B 1... (3 Replies)
Discussion started by: kingdbag
3 Replies
4. Shell Programming and Scripting
Using shell scripts, I use grep to find the word “error” in a log file:
grep error this.log.
How can I print or get the line 3 lines below the line that word “error” is located?
Thanks in advance for your response. (9 Replies)
Discussion started by: cbeauty
9 Replies
5. Shell Programming and Scripting
Hi
I have an AWK script that takes an input file and outputs it as CSV format.
The problem is its also outputting the characters at the top which are dashes(-------) and i want it to leave them out.
My script is as follows.
BEGIN {
count=1;
}
/^/ {
count+=1
if ( count > 2 ){... (3 Replies)
Discussion started by: magikminox
3 Replies
6. Shell Programming and Scripting
My files look like this
I need to remove the columns where dashes are the majority, if any of the sequences has any character in that particular position it should be removed too. The IDs and Freqs should be kept intact. Thus, the resulting file should look like this
Thanks in advance (14 Replies)
Discussion started by: Xterra
14 Replies
7. Shell Programming and Scripting
Hi again,
What i'm trying to accomplish here is search a large directory for certain filesames, read from a txt file and looping through it.
For instance, one of my target names from the loop file is:
1ad55f47-c342-496b-a46d-ba7de0f1b434
My loop is constructed thusly, run in a directory... (2 Replies)
Discussion started by: Karunamon
2 Replies
8. Shell Programming and Scripting
I need to remove dash (i.e. -) if present from positions 351-357, and then add - (dash) at 357th position. For example in following first and 3rd record we got
Before processing
1) 1st Record positions 351-357 = 0-12345
2) 3rd Record positions 351-357 = 00-4567
After processing:-
1) 1st... (7 Replies)
Discussion started by: lancesunny
7 Replies
9. UNIX for Dummies Questions & Answers
Hey Guys & Gals !
My script is creating a numbered list and I would like to have the numers and
results spaced apart by a tab.
Now to make sure it is clear which number corresonds with which outcome, I would like to have the tab space filled with dashes.
Anyone able to tell me if this... (6 Replies)
Discussion started by: TAPE
6 Replies
10. UNIX for Beginners Questions & Answers
My company has an email user group email address name that has 35 characters in front of the @ symbol where two of them are dashes. For some reason the mail command fails to send email to this address when I invoke it from the Linux command line. I don't understand the reason for the failure. Below... (5 Replies)
Discussion started by: Phil44
5 Replies
LEARN ABOUT LINUX
mailaddr
MAILADDR(7) Linux User's Manual MAILADDR(7)
NAME
mailaddr - mail addressing description
DESCRIPTION
This manual page gives a brief introduction to SMTP mail addresses, as used on the Internet. These addresses are in the general format
user@domain
where a domain is a hierarchical dot-separated list of subdomains. These examples are valid forms of the same address:
eric@monet.berkeley.edu
Eric Allman <eric@monet.berkeley.edu>
eric@monet.berkeley.edu (Eric Allman)
The domain part ("monet.berkeley.edu") is a mail-accepting domain. It can be a host and in the past it usually was, but it doesn't have to
be. The domain part is not case sensitive.
The local part ("eric") is often a username, but its meaning is defined by the local software. Sometimes it is case sensitive, although
that is unusual. If you see a local-part that looks like garbage, it is usually because of a gateway between an internal e-mail system and
the net, here are some examples:
"surname/admd=telemail/c=us/o=hp/prmd=hp"@some.where
USER%SOMETHING@some.where
machine!machine!name@some.where
I2461572@some.where
(These are, respectively, an X.400 gateway, a gateway to an arbitrary internal mail system that lacks proper internet support, an UUCP
gateway, and the last one is just boring username policy.)
The real-name part ("Eric Allman") can either be placed before <>, or in () at the end. (Strictly speaking the two aren't the same, but
the difference is beyond the scope of this page.) The name may have to be quoted using "", for example, if it contains ".":
"Eric P. Allman" <eric@monet.berkeley.edu>
Abbreviation.
Many mail systems let users abbreviate the domain name. For instance, users at berkeley.edu may get away with "eric@monet" to send mail to
Eric Allman. This behavior is deprecated. Sometimes it works, but you should not depend on it.
Route-addrs.
In the past, sometimes one had to route a message through several hosts to get it to its final destination. Addresses which show these
relays are termed "route-addrs". These use the syntax:
<@hosta,@hostb:user@hostc>
This specifies that the message should be sent to hosta, from there to hostb, and finally to hostc. Many hosts disregard route-addrs and
send directly to hostc.
Route-addrs are very unusual now. They occur sometimes in old mail archives. It is generally possible to ignore all but the "user@hostc"
part of the address to determine the actual address.
Postmaster.
Every site is required to have a user or user alias designated "postmaster" to which problems with the mail system may be addressed. The
"postmaster" address is not case sensitive.
FILES
/etc/aliases
~/.forward
SEE ALSO
binmail(1), mail(1), mconnect(1), aliases(5), forward(5), sendmail(8), vrfy(8)
RFC 2822 (Internet Message Format)
COLOPHON
This page is part of release 3.55 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
4.2 Berkeley Distribution 2004-09-15 MAILADDR(7)