Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Using awk, how to 'properly' print the rest of the string? Post 303045356 by newbie_01 on Wednesday 18th of March 2020 01:39:54 AM
Old 03-18-2020
Using awk, how to 'properly' print the rest of the string?

Hi,


Script below is working. But I want to put a "=" after the new date format BUT excluding the extra space Smilie

Code:
$ cat x.bash
#!/bin/bash
#

cat x.txt
echo

awk '
   BEGIN {
      split("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC", month, " ")
      for (i=1; i<=12; i++) mdigit[month[i]]=i
   }
   { m=substr($1,4,3)
     $1 = sprintf("%04d-%02d-%02d=",substr($1,8,4),mdigit[m],substr($1,1,2))
     print
   }' x.txt | sort | uniq > x.txt.00

cat x.txt.00
echo

Example run below:


Code:
$ ./x.bash
18-MAR-2020 04:28:13 * (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=

2020-03-18= 04:28:13 * (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=

Note the space after the day, trying to work out how to get rid of it Smilie The preferred output is


Code:
2020-03-18=04:28:13 * (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=

Tried this one below and still the same Smilie, still have the space



Code:
$1 = sprintf("%04d-%02d-%02d=",substr($1,8,4),mdigit[m],substr($1,1,2),substr($0,13))


Last edited by newbie_01; 03-18-2020 at 03:21 AM.. Reason: update code
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED Exclude Matches Between Pattern1 And Pattern2 Containing Pattern3 Print The Rest

Hi, From the sample file below Conditions 1) Pattern Range must start with "ALTER TABLE" 2) Pattern Range ends when it finds ";" 3) Between this range i want to select all the patterns that contain pattern " MOVE " Note : I would like to exclude the above pattern matches and print... (1 Reply)
Discussion started by: rajan_san
1 Replies

2. UNIX for Dummies Questions & Answers

AWK...find a string ,if so print it

Hi, I need to find a string, if it finds then I need to print it , otherwise it has to goto next line.... input is====> uid = shashi, india uid ,uid= asia uid= none, uid=india. none ========== output shold be uid = shashi, india uid , uid= asia uid= none, uid=india. none ... (1 Reply)
Discussion started by: hegdeshashi
1 Replies

3. Shell Programming and Scripting

Search a string and print the rest of line

Hi Guys, I need to search a string and print the rest of the lines... input: 8 0 90 1 0 59 20 2488 96 30006dde372 S ? 0:00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n output: 00 /etc/opt/SUNWconn/atm/bin/atmsnmpd -n Actually i don even need the first "00".. any suggestions is appreciated..... (13 Replies)
Discussion started by: mac4rfree
13 Replies

4. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

5. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

6. Shell Programming and Scripting

awk find and print next string

Can I do this in one awk session. Solution I have is poor. I want to return the number after PID. echo "Start: 12345 is used by PID:11111 username" | awk -F: '{print $3}' | awk '{print $1}' (6 Replies)
Discussion started by: u20sr
6 Replies

7. Shell Programming and Scripting

awk print string with removing all spaces

Hi all, I want to set 10 set of strings into a variable where: removing all spaces within each string change the delimiter from "|" to "," Currently, I've the below script like this:Table=`ten character strings with spaces in-between and each string with delimiter "|" | tr -d ' ' |... (7 Replies)
Discussion started by: o1283c
7 Replies

8. UNIX for Dummies Questions & Answers

Tree command does not print properly

Hi, when I run tree command in linux box getting below image, not the line test âââ lost+found âââ test1 â  âââ aaa.txt â  âââ bbb.txt âââ test2 3 directories, 2 files installed tree-1.5.3-2.el6.x86_64 package (8 Replies)
Discussion started by: stew
8 Replies

9. Shell Programming and Scripting

awk to print string if tag is specific value

In the below awk I am trying to print expName only if another tag planExecuted is true. In addition to the expName I am also printing planShortID. For some reason the word experiment gets printed so I remove it with sed. I have attached the complete index.html as well as included a sample of it... (1 Reply)
Discussion started by: cmccabe
1 Replies

10. Shell Programming and Scripting

awk print not working properly

Hello friends, There is one requirment where I need to login into database environment and pull all schema names into a text file ... as of now below are the schemas available... $> describe keyspaces; system_schema system_auth system abc system_distributed system_traces Now from... (4 Replies)
Discussion started by: onenessboy
4 Replies
DPKG-WWW(1)						      General Commands Manual						       DPKG-WWW(1)

NAME
dpkg-www - program to remotely open a WWW Debian package browser SYNOPSIS
dpkg-www [-s|--stdout] [-h|--host host] [query] DESCRIPTION
dpkg-www is used to remotely control a WEB browser and open a dpkg URL on the local host from an interactive shell or script. If the command is invoked while running under X-window the script will try to find an installed X browser to open the specified URL. If not running under X it will try to use a text browser instead. If Netscape is found and a Netscape instance is already running it will be asked to open the dpkg URL on localhost with the optional query supplied on the command line. If there is no browser running, it will start automatically a new one. The functionality provided by this program is identical to running a web browser with the -remote openURL(http://localhost/cgi-bin/dpkg) argument or opening the same URL from within the browser. dpkg-www-installer is an helper application which can configured in the WWW browser for web installation. It should never be invoked directly by the user. OPTIONS
-s, --stdout Redirect output to stdout. Requires one of the text browsers (lynx, lynx-ssl or links) installed. -h, --host host Send the query to a remote host, where dpkg-www must be installed. query Specifies an optional package name, an absolute pathname or a query argument which is passed to the dpkg cgi-bin. See dpkg-www(8) for more information about the use of the cgi. FILES
/etc/dpkg-www.conf ~/.dpkg-www Configuration files for dpkg-www. It is not necessary for these files to exist, there are sensible defaults for everything, but you can specify your preferred www browser with the DPKG_WWW_BROWSER variable, for example: DPKG_WWW_BROWSER=mozilla EXAMPLES
dpkg-www This would open a dpkg URL on localhost listing all the installed packages. dpkg-www bash This would open a dpkg URL asking info on the bash package. dpkg-www -h pisolo bash This would open a dpkg URL asking info on the bash package on host pisolo. dpkg-www 'dpkg*' This would open a dpkg URL listing all packages matching dpkg*. dpkg-www /bin/bash This would open a dpkg URL asking info on the package(s) owning the file /bin/bash . dpkg-www depends=svgalib This would open a dpkg URL listing all packages depending on svgalib. dpkg-www --stdout depends=awk | grep ^ii This would list on stdout all packages depending on awk and grep all lines of installed packages. SEE ALSO
dpkg(8), dpkg-www(8) AUTHOR
Massimo Dal Zotto <dz@debian.org>. Bugs should be reported via the normal Debian bug reporting system. LICENCE
dpkg-www is licensed under the GNU General Public License version 2. September 1, 2004 DPKG-WWW(1)
All times are GMT -4. The time now is 12:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy