Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

sed within awk statement

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 1 Week Ago   -   Original Discussion by sagar_1986
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 January 2018, 11:05 PM EST
Location: San Jose, CA, USA
Posts: 10,929
Thanks: 611
Thanked 3,819 Times in 3,263 Posts
There is almost never a need to invoke sed from awk (or even to use sed to filter output produced by awk. The awk editing functions can do most of the stuff sed can do and in this case, I find it easier to do it in awk than in sed. Your post #7 seems to ignore the suggestions provided in post #6. Please look at post #6 and let us know whether or not it works for you.
Sponsored Links
    #9  
Old Unix and Linux 1 Week Ago   -   Original Discussion by sagar_1986
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 January 2018, 3:28 AM EST
Location: Aachen, Germany
Posts: 11,966
Thanks: 354
Thanked 3,688 Times in 3,386 Posts
Quote:
Originally Posted by sagar_1986 View Post
. . .
As this input file is received from MySQL query,
. . .
that's why I proposed the MySQL- function DATE_FORMAT. For an SQL server, how about any of these (from this URL)


Code:
SELECT convert(varchar, getdate(), 126) — yyyy-mm-ddThh:mm:ss.mmm
                                        — 2008-10-02T10:52:47.513

— SQL create different date styles with t-sql string functions

SELECT replace(convert(varchar, getdate(), 111), ‘/’, ‘ ‘) — yyyy mm dd

The Following User Says Thank You to RudiC For This Useful Post:
sagar_1986 (1 Week Ago)
Sponsored Links
    #10  
Old Unix and Linux 1 Week Ago   -   Original Discussion by sagar_1986
sagar_1986's Unix or Linux Image
sagar_1986 sagar_1986 is offline
Registered User
 
Join Date: Apr 2012
Last Activity: 14 January 2018, 12:33 PM EST
Posts: 87
Thanks: 18
Thanked 0 Times in 0 Posts
Thanks sir,Don Cragun

This works perfect for me.

actually when I was replying to post no 5, post 6 came and when I read that I have posted thank you also.
Sorry for inconvenience because of me.

Sir, I am just a beginner in unix world, if you have any document regarding awk command, it would be very much helpful all newbies like me.

Thank you

---------- Post updated at 09:31 AM ---------- Previous update was at 09:21 AM ----------



Code:
 
 SELECT replace(convert(varchar, getdate(), 111), ‘/’, ‘ ‘) — yyyy mm dd

also works perfect
thanks

I have one doubt.

if column length is 20 and column variable length is variable say for one digit/ character to n character, then how to auto fit column lengh



Code:
 
 convert(varchar(19),column_name, 112)
 LEFT(column_length,15)




here we are fixing length to 19/15 but if column variable are of 4 digit only then how to auto fit column length, is it possible
    #11  
Old Unix and Linux 1 Week Ago   -   Original Discussion by sagar_1986
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 January 2018, 11:05 PM EST
Location: San Jose, CA, USA
Posts: 10,929
Thanks: 611
Thanked 3,819 Times in 3,263 Posts
As with any system-provided utility, the manual pages supplied with your system are always a good place to look to figure out how that utility works. You can start with:


Code:
man man

to see how the man command works, and environment variables and options you can set to control what pager is used to view the output it provides. Then move on to:


Code:
man awk

to see how awk works on your system.

If the man page whets your appetite and you want to dig a lot deeper, there are hundreds (if not thousands) of examples of awk scripts on this forum and you could try the books:
  • The AWK Programming Language by Aho, Alfred V., Kernighan, Brian W., Weinberger, Peter J. You might note that the initials of the three authors Aho, Weinberger, and Kernighan form the name of this utility; this is no accident--these three authors designed and wrote the utility as well as the book that describes it. Note that this book was written in 1988 which was before some of the current features provided by internationalized regular expressions and some extensions provided by later language maintainers were around, but it still provides a very good overview of how the language works with examples.
  • sed & awk by Dougherty, Dale and Robbins, Arnold. I haven't read this book myself, but others have given it good reviews.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert Update statement into Insert statement in UNIX using awk, sed.... dev123 Shell Programming and Scripting 0 03-22-2016 04:37 AM
If else statement in sed Madiouma Ndiaye Shell Programming and Scripting 5 01-21-2014 03:33 AM
Awk/sed problem to write Db insertion statement bhaskar_m Shell Programming and Scripting 6 08-27-2013 07:23 AM
Use awk/sed/grep with goto statement! dixits Shell Programming and Scripting 3 02-01-2012 06:35 AM
if and sed statement chris1234 Shell Programming and Scripting 3 04-26-2006 12:06 AM



All times are GMT -4. The time now is 04:29 AM.