Sponsored Content
Top Forums Shell Programming and Scripting Grep echo awk print all output on one line Post 302968881 by rwalker on Wednesday 16th of March 2016 02:38:23 AM
Old 03-16-2016
I apologize, I had assumed FILENAME was something I could change. I went back through what you suggested before, kept FILENAME, fixed the sub string and everything displayed exactly how I wanted it.

awk '/JUNOS/ && /boot/ {sub (/[^\/]* .$/, "", FILENAME); print FILENAME $5}' *cpe.domain.net/show.version

Thanks again for your assistance!

---------- Post updated at 02:38 AM ---------- Previous update was at 02:37 AM ----------

Just wanted to do a follow up since I'm at work and have had more time to play with this.

This script awk '/JUNOS/ && /boot/ {sub (/[^\/]* .$/, "", FILENAME); print FILENAME $5}' *cpe.domain.net/show.version got me started on what the boss wanted me to do.

Output:
Code:
device1-e0.cpe.domain.net/show.version[11.4R8.5]
device2-e0.cpe.domain.net/show.version[11.4R10.3]
device3-e1.cpe.domain.net/show.version[11.4R10.3]
device4-e0.cpe.domain.net/show.version[11.4R10.3]
device5-e1.cpe.domain.net/show.version[11.4R10.3]
device6-e0.cpe.domain.net/show.version[11.4R7.5]
device7-e1.cpe.domain.net/show.version[11.4R7.5]
device8-e0.cpe.domain.net/show.version[11.4R8.5]

From there, I had to change the way this prints so that it shows column 5 of show.version first, followed by a space, then the device name. After that, the boss wanted me to sort by the software version. Lastly, that script above left in some output I wasn't too fond of, particularly in showing /show.version at the end of each device name, so I had to cut that out. Below is the modified script meeting all the requirements, along with a sample of the output.

Script:
awk '/JUNOS/ && /boot/ {sub (/[^\/]* .$/, "", FILENAME); print $5 " " FILENAME}' *cpe.domain.net/show.version | sort -k5 | cut -d / -f 1

Output:
Code:
[10.0R4.7] device1-r0.cpe.domain.net
[10.0R4.7] device2-r0.cpe.domain.net
[10.0R4.7] device3.cpe.domain.net
[10.0R4.7] device4.cpe.domain.net
[10.0S6.1] device5-e0.cpe.domain.net
[10.0S6.1] device6-e0.cpe.domain.net
[10.1R4.4] device7-e0.cpe.domain.net
[10.1S1.3] device8.cpe.domain.net
[10.4R3.4] device9-r0.cpe.domain.net


Thanks again, RudiC! I definitely like the awk approach instead of the one I initially posted. Maybe I can get the boss on board with doing it that way too.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I output or echo NONE if grep does not find anything?

I am performing a grep command and I need to know how to echo "NONE" or "0" to my file if grep does not find what i am looking for. echo What i found >> My_File grep "SOMETHING" >> My_File I am sure this is easy, I am sort of new at this! Thanks (2 Replies)
Discussion started by: jojojmac5
2 Replies

2. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies

3. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

4. UNIX for Dummies Questions & Answers

Grep /Awk letters X - X in every line and print it as a mac address

hey i m kinda new to this so i will appreciate any help , i have this list of values: pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200 pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300 pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies

5. Shell Programming and Scripting

Print (echo) variable in a single line

Hi, I have written this code ------------------------------------------------ # !/bin/ksh i=0 while do j=$i while do echo -e $j #printf "%d",$j j=`expr $j - 1` done echo i=`expr $i + 1` done ---------------------------------------------------- The ouput which... (2 Replies)
Discussion started by: rac
2 Replies

6. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

7. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

8. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

9. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies

10. Shell Programming and Scripting

Echo print on same line while loop using variable

Currently using below script but echo it print the output in two line. Input file all-vm-final-2.txt CEALA08893 SDDC_SCUN DS_SIO_Workload_SAPUI_UAT_01 4 CEALA09546 SDDC_SCUN DS-SIO-PD5_Workload_UAT_SP1_Flash_07 4 CEALA09702 SDDC_SCUN DS-VSAN-RMP-WORKLOAD01 4 DEALA08762 SDDC_LDC... (3 Replies)
Discussion started by: ranjancom2000
3 Replies
sitewho(1)							   wzdftpd tools							sitewho(1)

NAME
sitewho - show current process information for each FTP session (wzdftpd) SYNOPSIS
sitewho [OPTION] DESCRIPTION
The sitewho command shows process information for all active wzdftpd connections, and a count of all connected users off of each server. OPTIONS
--user,-u XXX Use username XXX instead of wzdftpd. --pass,-w XXX Use password XXX with the username. --host,-h XXX Connect to the specified host. --port,-p XXX Employ the specified port number for connecting to the server. --secure,-s Enforce a secure connection, aborts if negotiation fails. --insecure,-t Do not try to negotiate a secure connection. AUTHORS
wzdftpd is written and maintained by Pierre Chifflier <chifflier@cpe.fr>, and some others contributors, full credits can be found in /usr/share/doc/wzdftpd/AUTHORS SEE ALSO
wzdftpd(8),ftp(1),siteconfig(1),siteuptime(1) Full documentation on wzdftpd, including configuration and FAQs, is available at http://www.wzdftpd.net For help/support, try the wzdftpd mailing lists, detailed on http://sourceforge.net/mail/?group_id=78247 Report bugs at http://www.wzdftpd.net/smf/index.php sitewho (wzdftpd) November 2004 sitewho(1)
All times are GMT -4. The time now is 03:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy