03-30-2011
AWK - Print partial line/partial field
Hello, this is probably a simple request but I've been toying with it for a while.
I have a large list of devices and commands that were run with a script, now I have lines such as:
a-router-hostname-C#show ver
I want to print everything up to (and excluding) the # and everything after it
the hostname portion is variable in size so basically I just want to find # and cut it and everything else after it to just end up with:
a-router-hostname-C
if I do a {print $1} I of course cut off the last field of "ver" but still have the "#show" portion.
Thanks in advance!
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
Id like to delete a line from a file using (preferably a single line unix command) if it contains a certain string pattern.
If line contains "abcdef" then delete that line.
Help greatly appreciated. (7 Replies)
Discussion started by: cronjob78
7 Replies
2. Shell Programming and Scripting
Hi,
I am having file which contains around 15 columns, i need to fetch column 3,12,14 based on the condition that column 3 starts with 40464
this is the sample data
how to achieve that (3 Replies)
Discussion started by: aemunathan
3 Replies
3. Shell Programming and Scripting
Hello,
Let's assume I have 100 files FILE_${m} (0<m<101). Each of them contains 100 lines and 10 columns.
I'd like to get in a file called "result" the average value of column 3, ONLY between lines 11 and 17, in order to plot that average as a function of the parameter m.
So far I can compute... (6 Replies)
Discussion started by: DMini
6 Replies
4. UNIX for Dummies Questions & Answers
hello all,
I wonder if anybody might be able to help with this.
I have file 1 and file2.
Both files may contain thousands of lines that have variable contents.
file1
234GH
5234BTW
89er
678tfg
234
234YT
tfg456
wert
78gt
gh23444 (7 Replies)
Discussion started by: Garrred
7 Replies
5. Shell Programming and Scripting
Hi Folks -
I'm quite new to awk and didn't come across such issues before. The problem statement is that, I've a file with duplicate records in 3rd and 4th fields. The sample is as below:
aaaaaa|a12|45|56
abbbbaaa|a12|45|56
bbaabb|b1|51|45
bbbbbabbb|b2|51|45
aaabbbaaaa|a11|45|56
... (3 Replies)
Discussion started by: asyed
3 Replies
6. Shell Programming and Scripting
if a variable has part of awk syntax stored in it. for eg: x=if($1>100)
can we substitute this variable in an awk statement.
based on above requirement can we execute something like:
awk '{x print $1}' infile (5 Replies)
Discussion started by: 47shailesh
5 Replies
7. Shell Programming and Scripting
I have test.xml XML file like
<Report account="123456" start_time="2014-09-08T00:00:00+00:00" end_time="2014-09-10T23:59:59+00:00" user="Dollar Tree" limit="1000000" more_sessions="some text ">
<Session ......rest of xml...............
I need output like
<Report>
<Session ......rest of... (3 Replies)
Discussion started by: kumars1331@gmai
3 Replies
8. Shell Programming and Scripting
Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :).
file
... (2 Replies)
Discussion started by: cmccabe
2 Replies
9. Shell Programming and Scripting
Trying to get the unique count of the below input, but if the text in beginning of $5 is a partial match to another line in the file then it is not unique.
awk
awk '!seen++ {n++} END {print n}' input
7 input
chr1 159174749 159174770 chr1:159174749-159174770 ACKR1
chr1 ... (2 Replies)
Discussion started by: cmccabe
2 Replies
10. UNIX for Beginners Questions & Answers
In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies
LEARN ABOUT NETBSD
rpc.bootparamd
RPC.BOOTPARAMD(8) BSD System Manager's Manual RPC.BOOTPARAMD(8)
NAME
bootparamd, rpc.bootparamd -- boot parameter server
SYNOPSIS
bootparamd [-ds] [-i interface] [-r router] [-f file]
DESCRIPTION
bootparamd is a server process that provides information to diskless clients necessary for booting. It consults the file ``/etc/bootparams''.
It should normally be started from ``/etc/rc''.
This version will allow the use of aliases on the hostname in the ``/etc/bootparams'' file. The hostname returned in response to the booting
client's whoami request will be the name that appears in the config file, not the canonical name. In this way you can keep the answer short
enough so that machines that cannot handle long hostnames won't fail during boot.
While parsing, if a line containing just ``+'' is found, and the YP subsystem is active, the YP map bootparams will be searched immediately.
OPTIONS
-d Display the debugging information. The daemon does not fork in this case.
-i interface
Specify the interface to become the default router. bootparamd picks the first IPv4 address it finds on the system by default. With
-i, you can control which interface to be used to obtain the default router address. -r overrides -i.
-s Log the debugging information with syslog(3).
-r Set the default router (a hostname or IP-address). This defaults to the machine running the server.
-f Specify the file to use as boot parameter file instead of ``/etc/bootparams''.
FILES
/etc/bootparams default configuration file
SEE ALSO
bootparams(5)
AUTHORS
Originally written by Klas Heggemann <klas@nada.kth.se>.
BUGS
You may find the syslog messages too verbose.
It's not clear if the non-canonical hack mentioned above is a good idea.
BSD
January 8, 1994 BSD